Forums

Form Validation Javascript Alert

bjames 25 Mar, 2010
I have my built-in ChronoForms mootools verification working properly, however, my users aren't seeing that there are errors when they submit (it involves scrolling up in order to see the field errors). I would like to add a line of code to jsvalidation2.js that will prompt a javascript alert window if there are any errors (in addition to the mootools prompts)...maybe something along the lines of:

if(errors==true){alert("There are errors with some of the information you have entered, please review your information above, and resubmit");}


Is this possible? How and where might I add this?

Any help is much appreciated!
GreyHead 25 Mar, 2010
Hi bjames,

It's before my breakfast here and I need my coffee but I think I posted a little script to do this a while ago. Try searching my posts on LV_INVALID (Google search may be more useful than the forum search).

Bob
bjames 25 Mar, 2010
Thanks for the quick reply, Bob. This is the only thread I could find on the topic: http://www.chronoengine.com/forums.html?cont=posts&f=2&t=14132 and it looks like this is for styling another div. What I'm looking for is a javascript pop-up alert. Where to add the conditional statement if there are 1 or more verification errors.

Thanks again!
GreyHead 25 Mar, 2010
Hi bjames,

Try this, add id='submit' to the submit button input and this code to the form JavaScript box:
window.addEvent('domready', function() {
  $('submit').addEvent('click', function() {
    if ( $$('.LV_invalid_field').length ) {
      alert('Oops!!');
    }
  }); 
});
It doesn't work until the second click on the submit button - I think that the validation must grab the first one. I've tested it with text inputs and I think it will work with other form elements too.

Bob
smoky 01 Apr, 2010
This was EXACTLY what I was trying to do, and this answer worked perfectly right off the bat! 😀 Now if only the Alert would pop up the first time the "submit" button was hit... :mrgreen:

Searches really work! 😲

P.S.
This is weird, but I tried this on another shorter form (all visible in one screen) and the Alert shows up immediately with the FIRST submit. The longer form, where the error is high up on the form, and not showing on the screen, it does take the 2nd submit to activate...

Here's the short form: http://oahq.org/index.php?option=com_chronocontact&Itemid=15
and here's the long form: http://oahq.org/index.php?option=com_chronocontact&Itemid=7
elehost 17 May, 2010
I too have been looking for a good solution to this problem without editing the source code.

The solution above requires two clicks so unfortunately it is not a good solution for me.

Does anyone else have some suggestions as to how to deal with the the issue of a long form not showing any error message when a user clicks the submit button (using the live validation)?

Thanks,

Paul
GreyHead 18 May, 2010
Hi Paul,

There are various solutions around.

[list]
  • Break the form into smaller chunks
  • Use a pop-up and fix the code so that it doesn't need two clicks.
  • Group the error messages at the end of the form.
  • Add a script to show a warning message near the Submit button.
  • Use a script to disable he submit button until the form is validated.
  • Add a script to switch focus back to the first invalid field.
  • [/list]
    Bob
    cjmicro 27 Apr, 2011
    this popup worked for me and even though they have to hit submit 2x it's better than nothing!

    Thanks!
    This topic is locked and no more replies can be posted.