Jump to content

PEAR HTML_Quickform help


8cc

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?
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.