RE: [PEAR] QF 3.2 - regex throwing errors
| From: | Mike Carter | Date: | Thu, 06 Nov 2003 09:11:49 +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-8805@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Alexey Borzov [mailto:borz_off@cs.msu.su]
>
> Hi!
>
> Mike Carter wrote:
> > 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.
>
> This works as expected:
>
> $form->addGroupRule('postcodeGroup', 'Postcode is required',
> 'required', null,
> 1, 'client');
Thanks, that gets the asteriks back, but I can't find a happy balance. Now
my additional regular expression rule causes the PHP warning:
Warning: preg_match() expects parameter 2 to be string, array given in
/usr/share/pear/HTML/QuickForm/Rule/Regex.php on line 61
The rule is defined:
$this->addGroupRule('postcodeGroup', array('postcode' => array(
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')
)));
I've also tried defining the rule as you did with the 'required' rule above,
$form->addGroupRule('postcodeGroup', 'Postcode is required',
'regex',
'/[a-zA-Z]{1,2}[0-9][0-9A-Za-z]{0,1} {0,1}[0-9][A-Za-z]{2}/', 1, 'client');
Both ways cause the same PHP warning and fail to let me proceed when
submitting the form.
I have to try and get this nailed before the afternoon today as work is
dropping on my head too fast :-( Can anybody with group rule validation
experience suggest/help? Please.
> Though I agree, rules will not suffer from more and better
> documentation...
There's so many niggly ways of setting things up to remember.
Regards,
Mike C.
________________________________________________________________________
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
________________________________________________________________________