Jump to content


Photo

PEAR HTML_Quickform help


  • Please log in to reply
1 reply to this topic

#1 8cc

8cc
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 21 April 2006 - 05:14 PM

First of all, I'm fairly new to PEAR's HTML_Quickform. I have the following group defined:
// 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');
When I submit the form with the above fields left blank, I get:
Your PRIMARY TELEPHONE # may only contain numbers.
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:
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" />

What am I doing wrong here?

#2 8cc

8cc
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 21 April 2006 - 05:54 PM

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:
$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'))));

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users