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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With