Jump to content
Updating IPB tonight Read more... ×

Archived

This topic is now archived and is closed to further replies.

8cc

PEAR HTML_Quickform help

Recommended Posts

First of all, I'm fairly new to PEAR's HTML_Quickform. I have the following group defined:
[code]// telephone #
$phone1_1_attrb = array('size' => 3, 'maxlength' => 3);
$phone1_2_attrb = array('size' => 3, 'maxlength' => 3);
$phone1_3_attrb = array('size' => 4, 'maxlength' => 4);
$group_phone1[] = &HTML_QuickForm::createElement('text', 'phone1_1', '', $phone1_1_attrb);
$group_phone1[] = &HTML_QuickForm::createElement('text', 'phone1_2', '', $phone1_2_attrb);
$group_phone1[] = &HTML_QuickForm::createElement('text', 'phone1_3', '', $phone1_3_attrb);
$form->addGroup($group_phone1, 'phone1', 'Primary Telephone #', array(')', '-'));
$form->addRule('phone1', 'Your PRIMARY TELEPHONE # is required.', 'required', NULL, 'client');
$form->addRule('phone1', 'Your PRIMARY TELEPHONE # may only contain numbers.', 'numeric', NULL, 'client');
$form->addRule('phone1', 'Your PRIMARY TELEPHONE # may not contain punctuation.', 'nopunctuation', NULL, 'client');[/code]
When I submit the form with the above fields left blank, I get:
[code]Your PRIMARY TELEPHONE # may only contain numbers.[/code]
It's acting as if there was a value entered, even though all 3 fields are blank.

Here is the HTML code generated for this part:
[code]Primary Telephone # <span style="color: #ff0000;">*</span><br />
(<input size="3" maxlength="3" name="phone1[phone1_1]" type="text" />)<input size="3" maxlength="3" name="phone1[phone1_2]" type="text" />-<input size="4" maxlength="4" name="phone1[phone1_3]" type="text" />[/code]

What am I doing wrong here?

Share this post


Link to post
Share on other sites
I checked the PEAR HTML_Quickform FAQ and found out that apparently, you HAVE to use addGroupRule() for a group, even though the documentation says you can use addRule() to validate the group as a whole.

Here's what I came up with:
[code]$phone1_1_attrb = array('size' => 3, 'maxlength' => 3);
$phone1_2_attrb = array('size' => 3, 'maxlength' => 3);
$phone1_3_attrb = array('size' => 4, 'maxlength' => 4);
$group_phone1[] = &HTML_QuickForm::createElement('text', 'phone1_1', '', $phone1_1_attrb);
$group_phone1[] = &HTML_QuickForm::createElement('text', 'phone1_2', '', $phone1_2_attrb);
$group_phone1[] = &HTML_QuickForm::createElement('text', 'phone1_3', '', $phone1_3_attrb);
$form->addGroup($group_phone1, 'phone1', 'Primary Telephone #', array(')', '-'));
$form->addGroupRule('phone1', array('phone1_1' => array(array('Your PRIMARY TELEPHONE # is required.', 'required', NULL, 'client'), array('Your PRIMARY TELEPHONE # may only contain numbers.', 'numeric', NULL, 'client'), array('Your PRIMARY TELEPHONE # may not contain punctuation.', 'nopunctuation', NULL, 'client')), 'phone1_2' => array(array('Your PRIMARY TELEPHONE # is required.', 'required', NULL, 'client'), array('Your PRIMARY TELEPHONE # may only contain numbers.', 'numeric', NULL, 'client'), array('Your PRIMARY TELEPHONE # may not contain punctuation.', 'nopunctuation', NULL, 'client')), 'phone1_3' => array(array('Your PRIMARY TELEPHONE # is required.', 'required', NULL, 'client'), array('Your PRIMARY TELEPHONE # may only contain numbers.', 'numeric', NULL, 'client'), array('Your PRIMARY TELEPHONE # may not contain punctuation.', 'nopunctuation', NULL, 'client'))));[/code]

It's fairly convoluted, but it seems to work.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.