我有一个表单,要求验证分两步完成。问题是表单在通过验证后没有提交给服务器。同时我想在提交后隐藏表单。提前谢谢。
以下是代码:
<form id="career-form" enctype="multipart/form-data" method="post" action="careers.php">
JS
submitHandler: function() {
$(form).before("<div id='message'></div>");
$('#message').html("<h2>Successufully submitted!</h2>");
$(form).hide();
}
var careerForm = {
showStepTwo: function(form) {
$("#step-one").hide();
$(form).show("drop", 1000);
},
validateFirst: function() {
$("#step-two").hide();
$("button.btn-link").click(function() {
form.validate("#career-form");
if ($("#career-form").valid()) {
careerForm.showStepTwo("#step-two");
}
return false;
});
},
validatePostCode: function() {
jQuery.validator.addMethod("postcodeUK", function(value, element) {
return this.optional(element) || /[A-Z]{1,2}[0-9R][0-9A-Z]? [0-9][ABD-HJLNP-UW-Z]{2}/i.test(value);
}, "Please specify a valid Postcode");
},
validateSecond: function() {
form.validate("#career-form");
careerForm.validatePostCode();
form.addRules("#address", {
required: true
});
form.addRules("#postcodeUK", {
required: true
});
form.addRules("#date", {
required: true,
date: true
});
form.addRules("#upload-file", {
required: true
});
},
validate: function() {
careerForm.validateFirst();
careerForm.validateSecond();
}
};