Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom submit function after jQuery Validation

How would I add a custom submit function to a form to prevent it's normal action but so that it only runs after being validated by the jQuery Validation plugin?

like image 742
Aaron Hathaway Avatar asked Nov 16 '10 20:11

Aaron Hathaway


1 Answers

You can use the submitHandler option of .validate(), like this:

$("form").validate({
  submitHandler: function(form) {
    //this runs when the form validated successfully
    form.submit(); //submit it the form
  }
});

There's also an invalidHandler if you want to run something when it doesn't pass validation.

like image 169
Nick Craver Avatar answered Sep 26 '22 00:09

Nick Craver