开发者

perform a set of functions after jQuery validate()

开发者 https://www.devze.com 2023-01-02 16:49 出处:网络
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'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.

0

精彩评论

暂无评论...
验证码 换一张
取 消