Re: Re: QuickForm dates

From: Date: Mon, 23 Jun 2003 17:48:05 +0000
Subject: Re: Re: QuickForm dates
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-6196@lists.php.net to get a copy of this message
Thanks for the help. I've got it working nicely now. It was a little confusing that the validation and required go on separate lines. Validation and required are not dependent -- you can do one without the other. Betrand previously posted this URL http://regexlib.com in another thread. Cheers Graham Here's what I did: // account expiration field
        $form->addElement('text', 'expire_date', 'Account Expiration');
        $input = &$form->getElement('expire_date');
        $input->setSize(15);
// user email field
        $form->addElement('text', 'email', 'Email');
        $input = &$form->getElement('email');
        $input->setSize(30);
// form validation for accnt expiration
        $form->addRule('expire_date', 'Please enter an axpiration date for this account', 'required');
        $form->addRule('expire_date', 'Expiration Date must in the format mm/dd/yyyy', 'regex', '^\d{1,2}\/\d{1,2}\/\d{4}$^');
// form validation for email
        $form->addRule('email', 'Please enter your email address','required');
        $form->addRule('email', 'Please enter a vaild email address', 'regex', '^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$^');
At 03:03 PM 6/23/2003 +0200, Bertrand Mansion wrote:
<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 -- PEAR General Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Graham Clarke GrahamC@53Tech.com www.53Tech.com 603.643.9955

« previous php.pear.general (#6196) next »