perform a set of functions after jQuery validate()
i'm using jQuery validate() plugin to validate a form. it does the validation but how do i perform a set of function if there are no errors?
i've tried this
$(document).ready(function() {
$('form').validate({
submitHandler: function(form) {
$.post('php/contact.php', {
开发者_开发百科 name: $('form #name').val(),
email: $('form #email').val(),
comments: $('form #comments').val() },
function(data) {
if(data.success) {
alert('thank you');
}
else {
alert('error');
}
}, 'json');
form.submit();
}
});
});
The form validates but i'm not getting data.success as true from php now. any ideas?
Use the submitHandler
option for this:
$("form").validate({
//rules, etc..
submitHandler: function(form) {
//do something, it was valid
}
});
The opposite handler for this is the invalidHandler
which executes when the submitted form was not valid.
精彩评论