Re: Quickform: Complex rule adding confusion

From: Date: Wed, 16 Jul 2003 21:32:30 +0000
Subject: Re: Quickform: Complex rule adding confusion
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-6632@lists.php.net to get a copy of this message
<mcarter@quantiv.com> wrote : > Hi, > > I've got a group of text boxes in a horizontal line. They break up the > entering of a reference number. I define them using: > > efNumber['ref'] = &HTML_QuickForm::createElement('text', > 'ref'); > $refNumber['ref']->setSize(8); > $refNumber['ref']->setMaxLength(8); > $refNumber['dash1'] = &HTML_QuickForm::createElement('static', > '', '', '-'); > $refNumber['check'] = &HTML_QuickForm::createElement('text', > 'check'); > $refNumber['check']->setSize(1); > $refNumber['check']->setMaxLength(1); > $refNumber['dash2'] = &HTML_QuickForm::createElement('static', > '', '', '-'); > $refNumber['applicant'] = &HTML_QuickForm::createElement('text', > 'applicant'); > $refNumber['applicant']->setSize(1); > $refNumber['applicant']->setMaxLength(1); > $form->addGroup($refNumber, 'referenceGroup', > $language['L_ReferenceNumber']); Lots of things could be optimised here, for a start. 1. addGroup() supports separators and array of separators so instead of adding them as static elements, use separators feature instead. 2. Instead of using setSize, setMaxLength, you can define attributes for your elements. The best way is to pass an array of attributes (array('maxlength' => 1)) > I then want to add rules to each of the boxes within the group. I found an > example of a "Complex" rule adding in the package but it doesn't seem to > work out for me. > > I attempt to add rules using the following code: > > $refRules['ref'][] = array($language['L_RequiredRefNot8Digits'], > array('regex', '/^[0-9]+$/')); > $refRules['ref'][] = array($language['L_RequiredRefNot8Digits'], > array('minlength',8)); > $refRules['ref'][] = array($language['L_RequireReferenceNumber'], > 'required'); > $refRules['check'][] = array($language['L_RequireReferenceNumber'], > 'required'); > $form->addGroupRule('referenceGroup', $refRules); > > However no rules seem to get applied to my input boxes. I can submit the > form freely - no javascript appears in the HTML. I'm starting to think I > may need to specify that the rules run on the client side - but how do I > specify this using the above rule adding technique? Look there for more info on form validation for groups, it might be clearer: http://www.appelsiini.net/~tuupola/php/peardoc2/package.html.html-quickform.. intro-validation.html You can add client validation by adding 'client' as a last parameter in your rule definition arrays. Bertrand Mansion Mamasam

« previous php.pear.general (#6632) next »