0

In my client-side code, I:

  1. Populate hidden fields in a form.
  2. Wait for the user to fill in fields such as Name, Email.
  3. The user clicks [Submit] or [Cancel].
  4. Assuming [Submit] was clicked, I assemble data, make a jQuery.ajax POST request, and repopulate the page with the result.

The various forms have reached enough complexity that the jQuery validation plugin http://bassistance.de/jquery-plugins/jquery-plugin-validation/ would be of great assistance. I have used it in various other projects.

However, I have never used it as part of a larger javascript/jQuery work flow. When the user clicks Submit, I want to run Validate against that html form (and only that form, there are several on the page). If validation fails, display the error messages (normal Validation behavior). If validation passes, continue on to my existing AJAX processing code.

How can I accomplish this, i.e., insert jQuery form validation between steps 3 and 4 above?

I apologize for not posting the code. It is subject to non-disclosure.

1 Answer 1

1

Use the submitHandler callback

"Callback for handling the actual submit when the form is valid. Gets the form as the only argument. Replaces the default submit. The right place to submit a form via Ajax after it validated."

$(".selector").validate({
   submitHandler: function(form) {
      // or put your code here
      $(form).ajaxSubmit();
   }
})
Sign up to request clarification or add additional context in comments.

1 Comment

Looks like that should do what I need. Thank you!

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.