Re: quickform - checking a valid date rule for a date element
| From: | Laurent Laville | Date: | Thu, 05 May 2005 13:42:00 +0000 |
| Subject: | Re: quickform - checking a valid date rule for a date element | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-19080@lists.php.net to get a copy of this message | ||
Hi Luke,
perharps you've forgot to define the qf_date element format, i means
something like :
$form->addElement('date', 'weddingdate', 'Wedding Date: ',
array('format' => 'M d Y', 'language' => 'en',
'minYear' => 2005, 'maxYear' => 2015
));
Myself i've used almost the same solution, but with uses of callback
$form->registerRule('isadate', 'callback', 'qfdate');
rather than function
$form->registerRule('isadate', 'function', 'qfdate');
Hope it will help !
Laurent Laville
Luke Barker a écrit :
Hi, I am using Quickform to display a date, and I want to check that the date selected by the user is a valid-date, using checkdate() . I have a date element, weddingdate: $form->addElement('date', 'weddingdate', 'Wedding Date: ', array('minYear'=>2005, 'maxYear'=>2015)); I made a custom rule - by making a function, then registering the rule: function qfdate($somedate) { if ($somedate['d'] != '' && $somedate['M'] != '' && $somedate['Y'] != '') {return checkdate($somedate['M'], $somedate['d'], $somedate['Y']);//nb order!} return false; // its not valid} $form->registerRule('isadate', 'function', 'qfdate'); then attaching the Rule to the date element: $form->addRule('weddingdate','Please enter a valid date', 'isadate'); // GroupRule or not? But it doesnt work - I have tried with a GroupRule and that didnt work either. When I output the parameter being passed to my function qfdate during the validation, it is a empty string. If it is done with the group rule the function is called 3 times as opposed to once for the normal rule. Any help or pointers appreciated! thanks Luke