我正在为我的一种表单使用 Jquery 验证引擎(https://github.com/posabsolute/jQuery-Validation-Engine)。验证运行良好,但即使字段值不符合验证,也无法阻止表单提交:
我有一个时事通讯 Sigunp 表格,如下所示:
<form id="submit-newsletter" method="POST" action="">
<input type="text" class="searchform validate[required, custom[email]]" value="Enter Your Email" id="email" name="nw-email" onblur="defaultInput(this);" onfocu s="clearInput(this);" />
<input type="hidden" id="newsletter" name="newsletter" value="nl" />
<input type="submit" class="submit" title="Signup" value="Sign Up" name="newsletter-signup" onclick="newsletterSubscribe(event);" />
</form>
该表单通过ajax提交如下:
// Newsletter Subscription Without Refresh
function newsletterSubscribe(e) {
e.preventDefault();
var dataString = 'nw-email=' + $('input[name=nw-email]').val() + '&newsletter=' + $('input[name=newsletter]').val();
$.ajax({
type: "POST",
url: "/newsletter/",
data: dataString,
success: function () {
$('#newsletter-box').html('<div id="message"></div>');
$('#message').html('<img width="18px" height="18px" src="/static/img/smtick.png" /><h5>Thank You !</h5>')
.append('<p>We have recieved your request. Please Check your mail for activation instructions. You will start recieving our newsletter once you have verified t his email address.</p>')
.hide()
.fadeIn(1200);
}
});
return false;
}
验证触发器如下:
$(document).ready(function() {
$('#submit-newsletter').validationEngine();
});
现在我可以看到验证错误消息,但是如果我按下提交按钮,无论值不是电子邮件地址,都会提交表单。
有任何想法吗 ?