Re: Quickform rules & documentation
| From: | Bertrand Mansion | Date: | Wed, 21 May 2003 17:25:31 +0000 |
| Subject: | Re: Quickform rules & documentation | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-5519@lists.php.net to get a copy of this message | ||
<mcarter@quantiv.com> wrote :
>
>
>> -----Original Message-----
>> From: Bertrand Mansion [mailto:bmansion@mamasam.com]
>>
>> <mcarter@quantiv.com> wrote :
>>
>>> Did I see somewhere that you can specify regular expressions to
>>> validate form field content? I can't find any examples of
>> it in use
>>> now!
>>>
>>> I wanted to check if a URL was valid using:
>>>
>> ^(http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?
>>> ([a-zA
>>> -Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*$
>>
>> $form->addRule('urlfield', 'URL not good, baby', 'regex',
>> '/^(http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-
>> Z0-9]*)?/?([a-
>> zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*$/');
>
> How do the extended parameters work in Quickform? Are they always checked
> in pairs? I've noticed some code contains ,null, in the parameter list as
> if it was a padding.
>
> I'm thinking about some of the single parameter ones such as 'client' and
> 'required'. Should they be provided along with a null to make the pair?
> Such as:
>
> $form->addRule('news_editor', 'Editors name is a required field',
> 'required', null, 'client', null);
$form->addRule('news_editor', 'Editors name is a required field',
'required', null, 'client');
The extra parameter is to be used only when you need to pass a format (ex: a
regex, a length, anything like an array etc.) to your validation function.
Regex, minlength, maxlength etc are predefined validation "functions". You
can use your own too, look at the examples.
> Or is $form->addRule('news_editor', 'Editors name is a required
> field',
> 'required', 'client'); fine?
PHP newbie ? :)
Bertrand Mansion
Mamasam