8cc Posted April 21, 2006 Share Posted April 21, 2006 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 https://forums.phpfreaks.com/topic/8056-pear-html_quickform-help/ Share on other sites More sharing options...
8cc Posted April 21, 2006 Author Share Posted April 21, 2006 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 https://forums.phpfreaks.com/topic/8056-pear-html_quickform-help/#findComment-29390 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.