Latox
Latox

Reputation: 4705

Best way to do jquery form validation?

Okay, so we have input boxes for the following:

firstname, lastname, email, password, city, state, captcha, terms and conditions

I've done the validation for all of these input boxes.

This validation is seperate for each ID, and works via change()

The e-mail and captcha use ajax, and if they are successful, it returns true.

I also have all of the validation inside the form submit()

But when the form is submitted, the validation on the ajax takes place again and the form is submitted WHILE the ajax request is processing.

How would I make the form delay submitting until the validation has ran and then auto submit? Like a sort of delay feature?

Each part of validation returns a var named error - error can either be true or false

If the error is false, it prevents form submit by returning false.

I've been thinking of scrapping the whole submit() validation, as its just a duplicate validation running on submit and basically running in a loop, and I was thinking of disabling the submit button with jquery unless everything is validated via change()?

Upvotes: 0

Views: 301

Answers (1)

Primus202
Primus202

Reputation: 646

Code excerpts would be handy but I'd say make your AJAX oncomplete function call your submit. Since you have multiple AJAX functions going on you may need to daisy chain them, i.e. when one finishes call the next and so on until the final one finishes and you call the submit function. Otherwise try having the AJAX only called once after field blur and not again on submit? Again, need to see code to understand what's really going on.

Upvotes: 2

Related Questions