7

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?

2 Answers 2

16

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.

Sign up to request clarification or add additional context in comments.

Comments

0

In the event handler return true to proceed and return false to stop.

1 Comment

There's no need to return true in any cases, return false is special, but an undefined (no return) will continue as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.