Re: Quickform and more complex dependent validation
| From: | Bertrand Mansion | Date: | Tue, 25 Feb 2003 13:12:36 +0000 |
| Subject: | Re: Quickform and more complex dependent validation | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-3948@lists.php.net to get a copy of this message | ||
<tobias.nix@web.de> wrote :
> I have got an HTML Form that similar looks like this:
>
> [FieldKey1] [FieldValue1]
> [FieldKey2] [FieldValue2]
> [FieldKeyX] [FieldValueX]
> [Submit]
>
> Example code:
>
> $field[] =& HTML_QuickForm::createElement('text', 'key1',
> 'key1');
> $field[] =& HTML_QuickForm::createElement('text', 'val1',
> 'val1');
> $form->addGroup($field, 'group1', 'Text Fields1:');
> $form->addGroupRule('group1' ,'Fill all fields' ,'required');
> $form->addGroupRule('group1' ,'Values must be numeric'
> ,'numeric');
>
> $field=null;
> $field[] =& HTML_QuickForm::createElement('text', 'key2',
> 'key2');
> $field[] =& HTML_QuickForm::createElement('text', 'val2',
> 'val2');
> $form->addGroup($field, 'group2', 'Text Fields2:');
> $form->addGroupRule('group2' ,'Fill all fields' ,'required');
> $form->addGroupRule('group2' ,'Values must be numeric'
> ,'numeric');
> [...]
>
> Now I want to add a new Group considering group1, group2, groupx.
> This group should be valid, if group1 or/and group2 is valid.
>
> The form should be valid if:
> 1. Add something to the KeyX field,
> also the ValueX field must be field.
> 2. Key and Value field must be numeric.
> 3. Only one pair (keyX, valueX) must be filled.
>
> Is this possible?
It's possible if you use a custom validation function in which you call
submitted values from the form. In this case, you need to have your form
object as global. Look at the example 3 in the docs/ directory.
Use addRule() because addGroupRule() doesn't support functions.
Good luck,
Bertrand Mansion
Mamasam