RE: [PEAR] QF 3.2 - regex throwing errors
| From: | Mike Carter | Date: | Thu, 06 Nov 2003 01:13:31 +0000 |
| Subject: | RE: [PEAR] QF 3.2 - regex throwing errors | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-8799@lists.php.net to get a copy of this message | ||
Hi,
Having attempted to switch to using addGroupRule() it seems to have caused
more problems. The on-line manual exmaple is different from example7 in the
archive. However I think I've implemented it the same....
$postcode[] = &HTML_QuickForm::createElement('text', 'postcode',
'',
array('size' => '25', 'maxlength' => '10',
'tabindex' => 2));
$postcode[] = &HTML_QuickForm::createElement('static', 'help', '',
$this->language['L_HelpPostcode'], $helpButton));
$this->addGroup($postcode, 'postcodeGroup',
$this->language['L_YourPostcode']);
// --- Form field rules
$this->addGroupRule('postcodeGroup', array('postcode' => array(
array($this->language['L_RequirePostcode'], 'required', null,
'client'),
array($this->language['L_InvalidPostcode'], 'regex',
'/[a-zA-Z]{1,2}[0-9][0-9A-Za-z]{0,1} {0,1}[0-9][A-Za-z]{2}/', 'client')
)));
Now the required field is not marked with an asteriks and no validation
appears to be executed, client or server side.
With regards to the validation and javascript on a group with a static
element - it has been working since I started using QF so must have become
broken with the new update. I need to get something up and working again
ASAP, any help in solving my issues would be appreciated..
Regards,
Mike C
> -----Original Message-----
> From: Bertrand Mansion [mailto:bmansion@mamasam.com]
>
> <mikeatwork@ukonline.co.uk> wrote :
>
> >
> >
> >> -----Original Message-----
> >> From: Bertrand Mansion [mailto:bmansion@mamasam.com]
> >>
> >> <mikeatwork@ukonline.co.uk> wrote :
> >>
> >>> Hi,
> >>>
> >>> Just upgraded to QF 3.2 and appear to be getting a regular
> >> expression
> >>> error now.
> >>>
> >>> I defined a rule to check if a postcode entered was valid:
> >>>
> >>> $this->addRule('postcodeGroup',
> >> $this->language['L_InvalidPostcode'],
> >>> 'regex', '/[a-zA-Z]{1,2}[0-9][0-9A-Za-z]{0,1}
> >> {0,1}[0-9][A-Za-z]{2}/',
> >>> 'client');
> >>
> >> Maybe because your postcodeGroup is a group ?
> >> Send the element declaration so we can check this..
> >
> > The declaration is as follows:-
> >
> > $postcode = array();
> > $postcode[] = &HTML_QuickForm::createElement('text',
> 'postcode', '',
> > array('size' => '25', 'maxlength' => '10',
> > 'tabindex' => 2));
> > $postcode[] = &HTML_QuickForm::createElement('static', '',
> > '',
> > str_replace('#helptext#', $this->language['L_HelpPostcode'],
> > $helpButton)); $this->addGroup($postcode, 'postcodeGroup',
> > $this->language['L_YourPostcode']);
> >
> >
> >>> When the form is submitted the validation appears to be
> executed on
> >>> the server side now (why?) and also kicks up the warning:
> >>
> >> Do you really wonder why we enforce server-side validation ? :)
> >
> > Heh. My query was because, the last time I checked before
> upgrading
> > to QF 3.2, javascript validation was being executed. Now its not.
>
> It's probably not executed because the generated javascript
> is wrong, look at the javascript source. Also, have a look at
> :
> http://pear.php.net/manual/en/package.html.html-quickform.intr
o-validation.p
hp
Specifically the part on group validation. It says: "To validate a group as
a whole, just use HTML_QuickForm::addRule(). All your elements will then be
validated one after the other using the same rule."
Your group has a static element, which causes problem if you use addRule().
You should use addGroupRule() and specify the rule only for your first
element. Look at the example 7 in docs/ too.
This is not a bug, but a misuse. I am surprised though that it was working
before... Probably because group validation was still incomplete.
Bertrand Mansion
Mamasam
--
PEAR General Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
________________________________________________________________________
This email has been scanned for all viruses by the MessageLabs Email
Security System. For more information on a proactive email security
service working around the clock, around the globe, visit
http://www.messagelabs.com
________________________________________________________________________