PEAR::HTML_QuickFrom - How do I do Group validation?
Using HTML_QuickForm how do I apply a group validation on two elements when there is no other validation errors? I'm trying to display one error message when username and/or password have a mismatch (invalid). I still want it to highlight each element within the group that has an error. Right now I'm trying to achieve this using AddFormRule(). However it's not working as this rule reports an error when technically it should not be an error until both username and password pass the other validation first (each field have a value, each field's value fit within the ranage length).
Any help would be much appreciated. If you require more information please let me know.
JeevesBond posted this at 12:22 — 12th May 2006.
He has: 3,956 posts
Joined: Jun 2002
Hi, I've never used this particular PEAR package before, so am taking stabs in the dark really!
Have you tried creating the elements as a group? As suggested in this part of the documentation: http://pear.php.net/manual/en/package.html.html-quickform.html-quickform.addgrouprule.php
I'm not very sure what you require either. Do you need it to validate both username and password then raise an error on each of them that's wrong? The problem being that it will raise an error on one of them and immediately stop validation and return the error?
It sounds like a complicated problem, so clarification would be good!
a Padded Cell our articles site!
The Warden posted this at 16:31 — 12th May 2006.
He has: 9 posts
Joined: Sep 2002
Yes AddGroupRule() you would think would be a good option. However it still doesn't provide me with what I require. See how I understand it and how I have it now all rules are validated as a whole each time the form is submitted. The username and password validate against the database shouldn't occur until all the other validations pass. If this is not done you get error messages that the username is invalid and password is invalid. Which is true but not entirely as the other validation rules have to be checked first and if they pass then check the username and password against the database together and is validated using AddFormRule(), custom validation via a function. See I have these rules presently.
<?php
$obForm->addRule('szUsername', 'Username required.', 'required');
$obForm->addRule('szUsername', 'Username must be 2 to 20 characters in length.', 'rangelength', array(2, 20));
$obForm->addRule('szPassword', 'Password required.', 'required');
$obForm->addRule('szPassword', 'Password must be 8 to 20 characters in length.', 'rangelength', array(8, 20));
?>
Then I have the custom validation against the database to check username and password together.
<?php
$obForm->AddFormRule(\"fnValidateCredentials\");
?>
If anyone else could help as well it would be much appreciated!
JeevesBond posted this at 17:15 — 12th May 2006.
He has: 3,956 posts
Joined: Jun 2002
Aha, so let me just clarify:
You have fields A and B being validated against some criteria and you also have fields C and D being validated against some criteria.
You want - using this PEAR library's API - to have A and B validated not only before C and D, but mutually exclusive to the validation of C and D?
So if, A and B fail validation the user should be advised of their failure, and the validator should not even try to check fields C and D, Is that correct?
Sorry for being pedantic, but knowing exactly what you need is half the battle!
a Padded Cell our articles site!
The Warden posted this at 18:01 — 12th May 2006.
He has: 9 posts
Joined: Sep 2002
Yes this is correct if you are referring to the letters as validation rules. There is only two fields, username and password. I have 5 validation rules in total. 4 validation rules should be validated and passed before validation rule 5 is checked. Which I'm guessing you are referring to C and D as.
JeevesBond posted this at 12:08 — 16th May 2006.
He has: 3,956 posts
Joined: Jun 2002
Sorry I haven't had time to reply sooner, as you can tell a lot has changed around here recently and we've all been a little busy!
(That's not "Busy" - the modrater - btw, just busy)
Anyway, have you solved your problem yet? I had another look through the documentation and had the thought that you could create two groups for validation, but call the function: validate() after creating the first group. If you do this before you even create the second group then it can't validate them right?
If the first group validation passes, then your code can go on and create the second group then validate that.
Does that make any sense? If you solved it in a different way, we'd love to hear how you did it!
a Padded Cell our articles site!
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.