Validate Two Fields

lapo78 02 Mar, 2011
Hi,
Can i validate two fields with V4, for example email and email confirmation?
Thanks
GreyHead 02 Mar, 2011
Hi Lapo,

Hmmm . . . Max hasn't included that in the Wizard but the library that he is using is FormCheck and that includes the Confirm check that does what you need. I guess that it must be possible to add this in the Form HTML but I'm not sure if you can add it through the Wizard.

Bob
Max_admin 04 Mar, 2011
Hi,

This can be done by adding a class to your element:
validate['%checkEqual']


and adding a JS snippet using a load JS action:

function checkEqual(el){
				if (el.value != $('confirm_email').value) {
					el.errors.push("Emails are not the same!");
					return false;
				} else {
					return true;
				}
			}


Where "confirm_email" is an id for the email confirmation field.

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
jumla16_guy 16 Mar, 2011
Works great till I hit the submit button. I'm checking the password fields and have assigned the "Enter Password" field a Field Class of validate['%checkEqual'] and then the "Verify Password" field a Field ID of confirm_password. I entered the JS code in the "Load JS" action as the last On Load event and this is what Firebug shows me for my <head> section:

[attachment=0]JS-Firebug.JPG[/attachment]

When I enter an incorrect password for VERIFY the JS works great.
However when correcting the mistake or entering the correct passwords the first time and on clicking the Submit button there is no error message and the page reloads itself with all the entered data still in place. The page scrolls down where I have a duplicate menu of the top, I'm assuming it's scrolling down to the Register menu item?
What have I missed?
jumla16_guy 16 Mar, 2011
Okay I changed the order of things a bit. I re-assigned the "Enter Password" field a Field ID of confirm_password and then the "Verify Password" field a Field Class of validate['%checkEqual']. So you enter a password and and enter the WRONG verification, as soon as you click anything else you get the JS generated error message.
However I still have the same problem of the page not re-directing? just reloading itself.
Max_admin 17 Mar, 2011
Hi,

This solution is only to show a "JS popup" error message when the 2 fields values are not the same, does this work ? if its working then this solution works ok and the other problem you have is something different which we can discuss in a different thread🙂

Let us know!

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
fullfusion 13 Apr, 2011
I just tested Max's solution and it does work.

Just so it's clear, in the first email field I put a Field Class of "validate['%checkEqual']" and then in the second email field I put a Field ID of "confirm_password". I entered the JS code Max provided above in a Load JS action as the last On Load event.

Thank you Max!

Dan
Max_admin 15 Apr, 2011
Thanks for confirming it works!!🙂

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
jumla16_guy 13 May, 2011
I could never get this to work when I had the "validate['%checkEqual']" in the 1st email field and then in the second email field, a Field ID of "confirm_email".

What happened everytime was that as soon as I clicked on the confirm email field, the 1st one would pop up with the error message. So I figured that by clicking into a blank confirm field, this wouldn't validate with the entry in the entry email field.

So I reversed it. In the entry email field I placed a Field ID of "email_required".
Then in the confirm email field I put a field class of "validate['%checkEqual']".
Then in Max's js code I changed the validate field from 'confirm_email' to 'email_required'.
Now when I click out of the confirm email box and there not the same I get the error message🙂

Thanks Max!
Max_admin 19 May, 2011
Hi jumla16_guy,

Thanks for sharing!🙂

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
brentmin 27 Nov, 2011
Hi Bob,

It would be very helpful if this functrionality could be added to the Form Wizard as soon as possible. It really is a core function on most forms today.

Much Appreciated.

Brent
brentmin 30 Apr, 2012
Thanks Max. This works just fine.
This topic is locked and no more replies can be posted.