我正在使用https://jqueryvalidation.org
中的jQuery验证插件实际表单本身并没有什么特别之处,它只是真正使用默认标记。
我遇到的问题是表单实际上并未在有效表单上提交,并且要求我再次单击“提交”按钮。我甚至尝试过将submitHandler
与form.submit()
一起使用
<form action="/search/" method="post" id="postcode-search">
<div class="input-wrap">
<input type="input" id="postcode" name="postcode" class="director-search" placeholder="Enter your Postcode here" required><br>
<div class="error-message"></div>
</div>
<button id="submit" type="submit" class="primary"><span class="inner"><i class="fa fa-search"></i> Search</span></button>
</form>
表单验证的代码在
之下 $('form#postcode-search').validate({
rules: {
postcode: {
required: true,
remote: {
url: theme_location + 'inc/postcode-validation.php',
type: 'post',
data: {
postcode: function() {
return $('input#postcode').val();
}
}
}
}
},
messages: {
postcode: {
required: 'Please provide a full postcode.'
}
}
});