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.
Forums
Comparing two form fields in validate
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
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
My two fields now look like this:
'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[/code]and when they're not equal, the form still posts.
<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]['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[/code]and when they're not equal, the form still posts.
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.
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.
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 :
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
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 :
|| ((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
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.
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.
Can you give me some idea of how to troubleshoot why the mootools verification setting isn't verifying?
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.
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.
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
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
It has only one class. It's online at http://ayendesigns.com/testing/visible-strategies/contact-us
Thanks.
Thanks.
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:
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:
Validation.addAllThese('validate-the_same_value', 'This field must be the same as the email field.', {
equalToField : 'email'
});
Bob
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.
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.
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 ?
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 ?
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
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.
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
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.
hi,
try replacing function(v) with : function (v,elm)
??
Max
try replacing function(v) with : function (v,elm)
??
Max
Nothing is ever that easy ... until now. Yup, that did it!
In looking at it before, I figured it needed elm as a parm... but thought that just adding it couldn't work, because how would the sending entity know to include it. Overthinking, I guess.
Thanks!! :cheer:
In looking at it before, I figured it needed elm as a parm... but thought that just adding it couldn't work, because how would the sending entity know to include it. Overthinking, I guess.
Thanks!! :cheer:
One final note... I changed it from
to
because otherwise simply leaving the verify field empty, when the email field is not, passes validation. I suppose another way to do it would be to remove that from the validation routine, and add 'required' to the class=
return Validation.get('IsEmpty').test(v) || ...
to
return !Validation.get('IsEmpty').test(v) || ...
because otherwise simply leaving the verify field empty, when the email field is not, passes validation. I suppose another way to do it would be to remove that from the validation routine, and add 'required' to the class=
Thanks for sharing this and for testing this with us!🙂
Best regards,
Max
Best regards,
Max
Hi, can you please look at my code - I did whatever needed (at least I think so), but it still doesn't work:
code:
<label>Password
<input type="password" name="password" id="password"/>
</label>
<label>Verify Password
<input class="validate-the_same_value" title="password" type="password" name="passwordagain" id="passwordagain" />
</label>
mooValidation.js
Validation.addAllThese([
['validate-the_same_value', 'Two passwords must be identical', function (v,elm) {
return (!Validation.get('IsEmpty').test(v) || ((elm.value == $(elm.getProperty('title')).value)? true : false ));
}],
code:
<label>Password
<input type="password" name="password" id="password"/>
</label>
<label>Verify Password
<input class="validate-the_same_value" title="password" type="password" name="passwordagain" id="passwordagain" />
</label>
mooValidation.js
Validation.addAllThese([
['validate-the_same_value', 'Two passwords must be identical', function (v,elm) {
return (!Validation.get('IsEmpty').test(v) || ((elm.value == $(elm.getProperty('title')).value)? true : false ));
}],
hi disciple,
all seems fine to me, I didn't test that code yet so no clue why it doesnt work, does all other validation types work fine with you ? can you add this code in moovalidation but after the required validation and not the first one ?
Cheers
Max
all seems fine to me, I didn't test that code yet so no clue why it doesnt work, does all other validation types work fine with you ? can you add this code in moovalidation but after the required validation and not the first one ?
Cheers
Max
Hi, thank you for your reply. Everything else works fine, I've added after and still no result.
Now the code looks like this:
Validation.addAllThese([
['required', 'This is a required field.', function(v) {
return !Validation.get('IsEmpty').test(v);
}],
['validate-the_same_value', 'Two passwords must be identical', function (v,elm) {
return (!Validation.get('IsEmpty').test(v) || ((elm.value == $(elm.getProperty('title')).value)? true : false ));
}],
['validate-number', 'Please enter a valid number in this field.', function(v) {
return Validation.get('IsEmpty').test(v) || (!isNaN(v) && !/^\s+$/.test(v));
}],
['validate-digits', 'Please use numbers only in this field. please avoid spaces or other characters such as dots or commas.', function(v) {
return Validation.get('IsEmpty').test(v) || !/[^\d]/.test(v);
}],
Now the code looks like this:
Validation.addAllThese([
['required', 'This is a required field.', function(v) {
return !Validation.get('IsEmpty').test(v);
}],
['validate-the_same_value', 'Two passwords must be identical', function (v,elm) {
return (!Validation.get('IsEmpty').test(v) || ((elm.value == $(elm.getProperty('title')).value)? true : false ));
}],
['validate-number', 'Please enter a valid number in this field.', function(v) {
return Validation.get('IsEmpty').test(v) || (!isNaN(v) && !/^\s+$/.test(v));
}],
['validate-digits', 'Please use numbers only in this field. please avoid spaces or other characters such as dots or commas.', function(v) {
return Validation.get('IsEmpty').test(v) || !/[^\d]/.test(v);
}],
I'm puzzled, I can't test it right now but will do soon, may be baalwww can post his moovalidation file for us here or you can PM him and see ?
Cheers
Max
Cheers
Max
This topic is locked and no more replies can be posted.