PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » HTML » HTML_QuickForm » Bug #1269

Compare validation on group elements

Details

Submitted2004-04-23 12:07 UTC
Frommaxen at tvattomaten dot se
StatusSuspended
PackageHTML_QuickForm
PHP Version4.3.6
OSWindows
Roadmaps(Not assigned)

Comments

[2004-04-23 12:07 UTC] maxen at tvattomaten dot se

Description:
------------
When using groups there is no easy way of using the compare as a group rule. Can't find a proper code example so I would be grateful if you fixed this bug or posted som docs on how to add the comparison.

Reproduce code:
---------------
$UName =& $form->createElement('text', 'username', 'User', array('size'=>10, 'maxlength'=>50));
$UPass =& $form->createElement('password', 'password', 'Password', array('size'=>10, 'maxlength'=>50));
$UCompPass =& $form->createElement('password', 'password_compare', 'Password compare', array('size'=>10, 'maxlength'=>50));
$form->addGroup(array($UName, $UPass, $UCompPass), 'uinfo', "Userinfo", '</tr><tr>', false);

$RegExUsernameText = '/^[a-zA-ZåäöÅÄÖé@!#£%&\.,:-_0-9\s]*$/';
$form->addGroupRule('uinfo', array(
'username' => array(
array('Username required', 'required', null, 'client')
),
array('password', 'password_compare') => array(
array('The passwords do not match', 'compare', null, 'client')
)
));

Expected result:
----------------
The passwords are not compared. Everything else works

[2004-05-10 15:04 UTC] maxen at tvattomaten dot se

Isn't possible to have something like:
$form->addGroupRule('uinfo', array(
'username' => array(
array('Username required', 'required', null, 'client')
),
'compare' => array(array('password', 'password_compare'), 'The passwords do not match', 'compare', null, 'client')
)
));

[2004-05-12 12:37 UTC] maxen at tvattomaten dot se

True. Perhaps there could be a check if there is a compare element, it's an ugly solution though. The compare rule is quite different from all other rules and another somewhat ugly solution might be to add a separate function for adding compare rules to elements. This would eliminate the problem and be less errorprone.

[2005-07-25 15:07 UTC] studio at peptolab dot com

Why does the 'compare' rule use a different interpretation
of the arguments anyway?

Consider:-

$form->addRule(array('cmpPasswd', 'cmpRepeat'), 'The
passwords do not match', 'compare', null, 'client');

vs

$form->addRule('cmpPasswd', 'The passwords do not match',
'compare', 'cmpRepeat', 'client');

Solves the problem neatly, does it not? For BC, the compare
rule needs only to determine if the first argument was an
array or not, and if not then simply recreate the array
using the value from the 'format' argument.