Re: Re: QuickForm dates
| From: | Bertrand Mansion | Date: | Mon, 23 Jun 2003 13:03:21 +0000 |
| Subject: | Re: Re: QuickForm dates | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-6191@lists.php.net to get a copy of this message | ||
<nntp@spacemonkeylabs.com> wrote :
> Graham Clarke wrote:
>
>> Hi - Some questions about using date fields:
>>
>> 1) What's the syntax for setting a default value for a date field like
>> this?
>>
>> $form->addElement('date', 'dob', 'DoB');
>
> $defaultValues['date'] = date('Y-m-d'); # '2003-06-23'
> $form->setDefaults($defaultValues);
>
> <hint>look at the examples</hint>
>
>> 2) If I want to use a regular text box for my date -- like below, how can
>> I validate it as a date??
>>
>> $form->addElement('text', 'dob', 'DoB');
>> $input = &$form->getElement('dob');
>> $input->setSize(15);
>> $input->setMaxLength(15);
>
> I don't think QuickForm does date validation. I suppose you could use
> ereg's to check that the year, month and date columns were relatively sane
> (or at least numeric).
>
> Anybody on the team have insight on this?
PHP has a checkdate() function. Or you could use the Validate package from
PEAR that has IIRC a date validation method, or use the Date package. Use
QuickForm registerRule() to use your custom validation function. Or search
the archive, this was already discussed before. Or you can even have a look
at the documentation here (up until the lazy doc builders wake up):
http://www.appelsiini.net/~tuupola/php/peardoc2/package.html.html-quickform..
intro-validation.html
Good luck,
Bertrand Mansion
Mamasam