在 AJAX 调用将信息发送到数据库之前,它不会进行验证。如何先激活验证?
$(document).ready(function() {
$("#signup").validationEngine('attach', {
promptPosition : "centerRight",
scroll : false,
ajaxFormValidation: true,
onBeforeAjaxFormValidation: beforeCall,
onAjaxFormComplete: ajaxValidationCallback,
});
});
$("#submit").click(function() {
var url = "insertintoDB.php"; // the script where you handle the form input.
$.ajax({
type: "POST",
url: url,
data: $("#signupform").serialize(), // serializes the form's elements.
success: function(data)
{
alert(data); // show response from the php script.
}
});
return false; // avoid to execute the actual submit of the form.
});
它确实指向 insertintoDB.php,但不验证以下表单。
<form class="form-horizontal" id="signup" name="signup" method="post" action="insertDB.php">
<div class="control-group">
<label class="control-label" for="inputSurname">Name</label>
<div class="controls"><input type="text" id="inputSurname" name="inputSurname" placeholder="Surname" class="validate[required]" /></div>
</div>
<button type="submit" id="submit" class="btn btn-success">Sign Up!</button>
</form>
如何在传递到 PHP 进行数据插入之前先验证它?