Buy Now
Sign in

client-side validation before submit

emmexx , March 09 at 08:02
e
emmexx

I need to do a rather complex validation before the user submits a form.
The form is built as a bunch of tabs where in every tab you have to enter name, surname, email, phone number.
The data in one of the tabs should be checked as the default contact. So, before submitting, I check if there's at least one default contact and if it has one of email or phone number. If those conditions are not satisfied I stop submission.

I can do that using the form tag and a javascript function but it is not very nice from a UI perspective: I use an alert to tell the user what is wrong and, even worse, the alert or the function, I don't know, break the tabs. The content of the tabs becomes hidden, only the tabs anchors remain visible.

I'd like a solution similar to the standard cf validation: if the form doesn't validate I'd like the focus to go to the default contact check of the current tab and a tooltip displayed.
Is there a way to accomplish that?
I tried to understand the inner workings of gvalidation.js and of the code inside the form but without documentation it is just painful reverse engineering.

Thank you

maxx

GreyHead

Hi Maxx,

I would probably try to do this by attaching a custom validation to say the name of the default contact, or possibly a later field as the email and phone will still be blank then.I'm not sure how to trigger a custom CF validation from the submit button.

If this doesn't work it might be simpler to use a different validation library that has more options and can handle this setup.

Bob

ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much

e
emmexx

GreyHead:

If this doesn't work it might be simpler to use a different validation library that has more options and can handle this setup.


Thank you Bob.

Do you have any suggestion about a library that works well with cf5?

maxx

GreyHead

Hi Maxx,

I have used the jQuery .validate library a few times - it did what I needed.

Bob

ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much