我在Bootstrap模式中创建了一个用于用户帐户注册的表单:
<div class="modal-body">
<form class="form-horizontal" id="registerForm">
<div class="form-group">
<label for="newUsername" class="control-label col-xs-3">Username</label>
<div class="col-xs-9">
<input type="text" class="form-control" id="newUsername" required>
</div>
</div>
<div class="form-group">
<label for="newPassword" class="control-label col-xs-3">Password</label>
<div class="col-xs-9">
<input type="password" class="form-control" id="newPassword" required>
</div>
</div>
<div class="form-group">
<label for="newPassword2" class="control-label col-xs-3">Password</label>
<div class="col-xs-9">
<input type="password" class="form-control" id="newPassword2" required>
</div>
</div>
<div class="form-group">
<label for="newEmail" class="control-label col-xs-3">E-mail</label>
<div class="col-xs-9">
<input type="email" class="form-control" id="newEmail" required>
</div>
</div>
</form>
</div>
的Ajax
$(document).on('submit', '#registerForm', function () {
var username = $("#newUsername").val();
var password = $("#newPassword").val();
var email = $("#newEmail").val();
$.post("registration.php", { new_user: username, new_psw: password, new_email: email}, function(data) {
var result = $.parseJSON(data);
if (result.error) {
if (result.err_code == 1) {
$('#newUsername').css({"border": "2px solid red", "box-shadow": "0 0 3px red"});
}
else if (result.err_code == 2) {
$('#newEmail').css({"border": "2px solid red", "box-shadow": "0 0 3px red"});
}
}
});
event.preventDefault();
});
我想整合SolveMedia验证码,我按照以下步骤操作:https://portal.solvemedia.com/portal/help/pub/php/
所以我在</form>
标记之前添加了以下代码:
<div class="form-group">
<label class="control-label col-xs-3">Captcha code</label>
<div class="col-xs-9">
<?php echo solvemedia_get_html("my_key"); ?>
</div>
</div>
<?php echo solvemedia_get_html("my_key"); ?>
<textarea name="adcopy_challenge" rows="3" cols="40"></textarea>
<input type="hidden" name="adcopy_response" value="manual_challenge"/>
问题是表单处理文件没有检索SolveMedia POST字段:
$_POST["adcopy_challenge"]
$_POST["adcopy_response"]
位于SolveMedia library file(我包含在我的PHP文件中)。
因此我的表单会发送除SolveMedia POST值之外的所有值。
根据帮助部分(https://solvemedia.zendesk.com/hc/en-us/articles/203660514-Always-Receiving-incorrect-solution-),我必须确保该表单包含POST方法。 Bootstrap表单中缺少的method="POST"
可能是问题吗?
答案 0 :(得分:1)
以下是提交表单的Ajax代码
<form id="myform2" class="formValidation" name="myform2" action="" method="post"></form> <!-- this is the form for the <div> in html5 -->
<div class="widget-body">
<div class="widget-main">
<div>
<label for="form-field-select-1">Comune</label>
<select name="comune" class="form-control" id="form-field-select-1" form="myform2">
<option value="">Seleziona...</option>
<?php
$comune = "SELECT * FROM tbl_comune ORDER BY nome_comune ASC";
$result_comune = dbQuery($comune);
if (dbNumRows($result_comune) > 0) {
while($row_comune = dbFetchAssoc($result_comune)) {
extract($row_comune);
?>
<option value="<?php echo $id_comune; ?>"><?php echo $nome_comune; ?></option>
<?php
}
} else {
?>
<option value="">Non ci sono dati</option>
<?php
}
?>
</select>
</div>
<hr>
<div class="widget-body">
<div class="widget-main">
<div>
<input type="text" name="comune" id="comune" value="" placeholder="Aggiungi Comune" form="myform2">
<input type="submit" name="submit" value="Submit" class="btn btn-sm btn-success" form="myform2">
<div class="result"></div>
</div>
</div>
</div>
</div>
</div>
如果您仔细观察,则为$(document).on('submit', '#registerForm', function () {
var username = $("#newUsername").val();
var password = $("#newPassword").val();
var email = $("#newEmail").val();
$.post("registration.php", { new_user: username, new_psw: password, new_email: email}, function(data) {
var result = $.parseJSON(data);
if (result.error) {
if (result.err_code == 1) {
$('#newUsername').css({"border": "2px solid red", "box-shadow": "0 0 3px red"});
}
else if (result.err_code == 2) {
$('#newEmail').css({"border": "2px solid red", "box-shadow": "0 0 3px red"});
}
}
});
event.preventDefault();
});
,var
和username
分别创建了3 password
,但email
没有var
你需要像
SolveMedia POST fields
SolveMedia POST fields
一旦你在这里用Ajax创建var username = $("#newUsername").val();
var password = $("#newPassword").val();
var email = $("#newEmail").val();
var challenge = $("[name='adcopy_challenge']").val();
var response = $("[name='adcopy_response']").val();
发布它的值以及其他输入值
SolveMedia POST fields var
并在PHP端获取$.post("registration.php", { new_user: username, new_psw: password, new_email: email, challenge: adcopychallenge, response: adcopyresponse }
SolveMedia POST fields