RE: [PEAR] Quickform Validation rules for grouped elements
| From: | Mike Carter | Date: | Tue, 27 May 2003 10:10:38 +0000 |
| Subject: | RE: [PEAR] Quickform Validation rules for grouped elements | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-5610@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Bertrand Mansion [mailto:bmansion@mamasam.com]
>
> <mcarter@quantiv.com> wrote :
>
> > Hello again,
> >
> > Just getting a little confused by the amount of nested
> arrays needed
> > for
> > addGroupRule() !
> >
> > I've defined a sub-group in my Quickform using...
> > $name['news_linkurl'] = &HTML_QuickForm::createElement('text',
> > 'news_linkurl', 'URL:');
> > $name['news_linkurl']->setSize(20);
> > $name['news_linkname'] = &HTML_QuickForm::createElement('text',
> > 'news_linkname', 'Title:');
> > $name['news_linkname']->setSize(30);
> > $form->addGroup($name, 'news_link', 'Associated website');
> >
> > I then want to add two rules to each of the text elements.
> I've just
> > tried...
> >
> > $form->addGroupRule('news_link', array(
> > 'news_linkurl' => array(array('Related URL is not well formed',
> > 'regex',
> >
> "^(http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/
> > ?([a-z
> > A-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*$")),
> > 'news_linkname' => array(array('URL Title must be at least 5
> > characters', 'minlength', '5'))
> > ));
> >
> > When I submit my form I get a PHP warning displayed at the top:-
> > Warning: No ending delimiter '^' found in
> > c:\php4\pear\HTML\QuickForm.php on line 1452
>
> Must be something wrong with your regex.
As I didn't write the regex myself, it was published on a website I was
pretty confident it wasn't a mess up in that which generated the PHP error:
Warning: No ending delimiter '^' found in c:\php4\pear\HTML\QuickForm.php on
line 1452
This morning I generated a test using the same regular expression. See the
code (try changing the url variable to test) :-
<?php
$url = "http://www.dogs.com";
if(eregi('^(http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*
)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*$', $url))
{
print "You have a valid URL!";
} else {
print "Your have a bad URL!";
}
?>
This works perfect with no warnings or errors. Because of this, I think
there is something screwy going on with the way Quickform is handling or
storing the regular expressions passed in as validation rules.
Regards,
Mike C.
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.480 / Virus Database: 276 - Release Date: 5/12/2003
________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________