Comparing two form fields in validate

Post any questions you may have here

Comparing two form fields in validate

Postby baalwww on Wed Jul 16, 2008 7:53 pm

I have a typical Contact Us form, with two fields Email and Verify Email. I need the validation to compare the two, and fail if they are not equal.
baalwww
Fresh Boarder
 
Posts: 11
Joined: Wed Jul 16, 2008 4:35 pm

Re:Comparing two form fields in validate

Postby admin on Wed Jul 16, 2008 8:15 pm

ok, step #1- add this class to the tag of the verify email field:

class="validate-the_same_value" title="email_field_id"

open mooValidation.js under components/com_chronocontact/js/

after this line :
Validation.addAllThese([

add :

['validate-the_same_value', 'Please use letters only (a-z) in this field.', function (v) {
return Validation.get('IsEmpty').test(v) || ((elm.value == $(elm.getProperty('title')).value)? true : false )
}],

Let me know!

Cheers

Max
ChronoForms Developer Thanks for using ChronoForms.
If you have any problems with ChronoForms please tell us.
If you like ChronoForms please post a review at Joomla.org
Want users to submit their content to your website ? try Submit Story
Want to list/edit/delete your data ? try ChronoConnectivity
User avatar
admin
Platinum Boarder
 
Posts: 2127
Joined: Mon Aug 14, 2006 5:29 am

Re:Comparing two form fields in validate

Postby baalwww on Wed Jul 16, 2008 8:45 pm

My two fields now look like this:
Code: Select all
<tr>
  <td style='width: 120px'>Email:</td>
  <td><input type='text' class='required' name='email'
    value='<?php echo $_POST['email'];?>'></td>
</tr>
<tr>
  <td style='width: 120px'>Verify email:</td>
  <td><input type='text'  name='vemail'
    class='validate-the_same_value' title='email'></td>
</tr>
and the line in the code, right before the 'required' code is...
Code: Select all
['validate-the_same_value',
  'This field must contain the same value as Email.',
  function (v) {
    return Validation.get('IsEmpty').test(v)
      || ((elm.value == $(elm.getProperty('title')).value)
        ? true : false )
  }],
['required
and when they're not equal, the form still posts.
baalwww
Fresh Boarder
 
Posts: 11
Joined: Wed Jul 16, 2008 4:35 pm

Re:Comparing two form fields in validate

Postby baalwww on Thu Jul 17, 2008 3:03 am

Here's what I've done to check it...

I noticed no matter what I put in Verify Email, it wasn't verifying. So I put an alert at the start of the verification, and it never hits it.

Then I noticed that the Verification library was set to Prototype, so I changed it to mootools ... after which NOTHING verified, ever the empty required fields.
baalwww
Fresh Boarder
 
Posts: 11
Joined: Wed Jul 16, 2008 4:35 pm

Re:Comparing two form fields in validate

Postby admin on Thu Jul 17, 2008 8:40 am

Hi,

Ok, actually you should also have id='email' in the EMail field tag!

next, if this didnt work, try this, remove this from the validation function :
Code: Select all
|| ((elm.value == $(elm.getProperty('title')).value)? true : false )


then test that the Verify email field is getting validated for being not Empty and all other validations are fine, if it worked then the problem is with this last part and we will fix it, sorry but I didn't set on my office PC to check this yet!

Cheers

Max
ChronoForms Developer Thanks for using ChronoForms.
If you have any problems with ChronoForms please tell us.
If you like ChronoForms please post a review at Joomla.org
Want users to submit their content to your website ? try Submit Story
Want to list/edit/delete your data ? try ChronoConnectivity
User avatar
admin
Platinum Boarder
 
Posts: 2127
Joined: Mon Aug 14, 2006 5:29 am

Re:Comparing two form fields in validate

Postby baalwww on Thu Jul 17, 2008 12:51 pm

I'm afraid we'll need to take this one step at a time... I did add the 'id' to the email tag, I had noticed that the code was looking for it and it wasn't there. That didn't make a difference.

The fact is, I have backed out the entire addition from the .js file, putting it back to the way it was. The two fields prior to the email fields in my form are both required. When I set validation to prototype, and attempt to tab from the first empty field to the second, I am told that the field is required. When I set validation to use mootools and do the same, there is no validation.

Whatever is preventing mootools from validating, I expect, is making us think the new routine is not working too.
baalwww
Fresh Boarder
 
Posts: 11
Joined: Wed Jul 16, 2008 4:35 pm

Re:Comparing two form fields in validate

Postby baalwww on Thu Jul 17, 2008 10:32 pm

Can you give me some idea of how to troubleshoot why the mootools verification setting isn't verifying?
baalwww
Fresh Boarder
 
Posts: 11
Joined: Wed Jul 16, 2008 4:35 pm

Re:Comparing two form fields in validate

Postby baalwww on Fri Jul 18, 2008 2:13 pm

Ok. Have mootools validate working now. Turns out my default editor was not treating the end-of-line correctly.

So, now all the normal validation works. What's not happening, is the new routine is not being invoked by class=... in the tag. I even changed it to have the validation return a value no matter what, to cause the validation to fail, and... nothing.
baalwww
Fresh Boarder
 
Posts: 11
Joined: Wed Jul 16, 2008 4:35 pm

Re:Comparing two form fields in validate

Postby GreyHead on Sat Jul 19, 2008 9:14 am

Hi Baalwww,

Please check the page source and make sure that there is only one class attribute in the tag. Is the page on-line so I can take a quick look?

Bob
Bob Janes
info at greyhead.net
ChronoForms Support If you like ChronoForms please vote or post a review at Joomla.org
User avatar
GreyHead
Platinum Boarder
 
Posts: 3251
Joined: Tue May 29, 2007 10:15 pm
Location: Brittany

Re:Comparing two form fields in validate

Postby baalwww on Sat Jul 19, 2008 2:57 pm

It has only one class. It's online at http://ayendesigns.com/testing/visible-strategies/contact-us

Thanks.
baalwww
Fresh Boarder
 
Posts: 11
Joined: Wed Jul 16, 2008 4:35 pm

Re:Comparing two form fields in validate

Postby GreyHead on Sat Jul 19, 2008 3:08 pm

Hi baalwww,

I took a quick look and I can't see how the script knows which field to compare with . . . maybe there's a parameter missing.

Bob

Later: looking at the the help page Maybe you need:
Code: Select all
Validation.addAllThese('validate-the_same_value', 'This field must be the same as the email field.', {
    equalToField : 'email'
});
Bob
Bob Janes
info at greyhead.net
ChronoForms Support If you like ChronoForms please vote or post a review at Joomla.org
User avatar
GreyHead
Platinum Boarder
 
Posts: 3251
Joined: Tue May 29, 2007 10:15 pm
Location: Brittany

Re:Comparing two form fields in validate

Postby baalwww on Sat Jul 19, 2008 4:16 pm

The Verify Email field passes a Title of 'email'. The script uses the title field of the verified field to use as the id of the field to compare, and the email field has an id of 'email'.

However, that's not the problem.

If I just remove all of the test in the script, and replace it with returning a value to fail the validation, it does not... it's not being invoked by "class=" in the verified field.
baalwww
Fresh Boarder
 
Posts: 11
Joined: Wed Jul 16, 2008 4:35 pm

Re:Comparing two form fields in validate

Postby admin on Sat Jul 19, 2008 5:11 pm

Hi baalwww,

did you try Bob's last code edit above ? maybe it will work ? whats the main problem we have now ? you say that class is not triggered, what if you added class="required" to the verify email address field, does it get validated ?
ChronoForms Developer Thanks for using ChronoForms.
If you have any problems with ChronoForms please tell us.
If you like ChronoForms please post a review at Joomla.org
Want users to submit their content to your website ? try Submit Story
Want to list/edit/delete your data ? try ChronoConnectivity
User avatar
admin
Platinum Boarder
 
Posts: 2127
Joined: Mon Aug 14, 2006 5:29 am

Re:Comparing two form fields in validate

Postby baalwww on Sat Jul 19, 2008 5:41 pm

Hi. Okay, here's where I am:

1. I changed the class to required, and it DOES fire.

2. I changed class back to the original, and changed the code in the validation routine to return false, and it DOES fire and fail validation.

So, it appears to be a problem with the code. I'm suspecting that
Code: Select all
elm.value == $(elm.getProperty('title')).value)
is not evaluating.

I tried putting an alert just prior to the return, to see what it is evaluating to, and I get an error in firebug that elm does not exist.
baalwww
Fresh Boarder
 
Posts: 11
Joined: Wed Jul 16, 2008 4:35 pm

Re:Comparing two form fields in validate

Postby admin on Sat Jul 19, 2008 6:52 pm

hi,

try replacing function(v) with : function (v,elm)

??

Max
ChronoForms Developer Thanks for using ChronoForms.
If you have any problems with ChronoForms please tell us.
If you like ChronoForms please post a review at Joomla.org
Want users to submit their content to your website ? try Submit Story
Want to list/edit/delete your data ? try ChronoConnectivity
User avatar
admin
Platinum Boarder
 
Posts: 2127
Joined: Mon Aug 14, 2006 5:29 am

Next

Return to Questions & Answers

Who is online

Users browsing this forum: Google [Bot], GreyHead, Yahoo [Bot] and 4 guests