基本上,当我点击提交时,它会将我发送到下一页而不是阻止帖子。它甚至不再验证,所以这也需要发生。我该如何解决这个问题?
Javascript:
<script language="javascript" type="text/css">
jQuery.validator.addMethod(
"noStateSelected",
function(value, element) {
if (element.value == "")
{
return false;
}
else return true;
},
""
);
jQuery.validator.messages.required = "";
$(document).ready(function(){
$("#newMemberForm").validate({
invalidHandler: function(e, validator) {
var errors = validator.numberOfInvalids();
if (errors) {
var message = errors == 1
? 'You missed 1 field. It has been highlighted below.'
: 'You missed ' + errors + ' fields. They have been highlighted below.';
$("div.error span").html(message);
$("div.error").show();
} else {
$("div.error").hide();
}
},
submitHandler: function() {
$(#newMemberForm).submit();
},
errorLabelContainer: "#messageBox",
wrapper: "li",
onkeyup: false,
submitHandler: function() {
$("div.error").hide();
$("label.error").remove();
},
rules: {
sponsor: "required",
username: "required",
password: "required",
first_name: "required",
last_name: "required",
phone_number: "required",
tax_id: "required",
address_1: "required",
city: "required",
postal_code: "required",
profile_stateList: {
noStateSelected: true
},
email: {
required: true,
email: true
},
terms_conditions: "required"
},
messages: {
email: {
email: "Your email address must be in the format of name@domain.com ."
},
terms_conditions: "You must agree with the conditions."
}
});
});
</script>
HTML:
<form name="newMember" id="newMemberForm" action="~secure_url~/cgi-bin/xflow/newuser.cgi" method="POST">
....
[Conditional input text box required if it exists]
...
</form>
答案 0 :(得分:1)
您的提交操作有一个错误的选择器(您缺少引号):
submitHandler: function() {
$(#newMemberForm).submit();
},
应该是:
submitHandler: function() {
$("#newMemberForm").submit(); // Quotes here
},
答案 1 :(得分:1)
我的愚蠢问题,我做了text / css类型。它已被修复。