Home > Archive > PHP Pear > May 2005 > quickform - checking a valid date rule for a date element
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
quickform - checking a valid date rule for a date element
|
|
| Luke Barker 2005-05-05, 3:57 pm |
| 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'=3D>2005, 'maxYear'=3D>2015));
I made a custom rule - by making a function, then registering the rule:
function qfdate($somedate)
{
=09=09=09=09
=09=09=09=09
=09if ($somedate['d'] !=3D '' && $somedate['M'] !=3D '' && $somedate['Y'] !=
=3D '') {
=09=09=09=09 =20
=09 return checkdate($somedate['M'], $somedate['d'], $somedate['Y']);
//nb order!
=09=09=09 =20
=09}
=09 return false; // its not valid
}
=09=09=09=09
$form->registerRule('i ate', 'function', 'qfdate');
then attaching the Rule to the date element:
$form->addRule('weddingdate','Please enter a valid date', 'i ate');
// 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
=09=09=09=09=09=09=09 =20
--=20
~L~
lukebarker@gmail.com
http://www.battez.org
---------------------------------------
I'm doggone gonna be with
Some real people...
( R & E )
| |
| Laurent Laville 2005-05-05, 3:57 pm |
| 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('i ate', 'callback', 'qfdate');
rather than function
$form->registerRule('i ate', '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('i ate', 'function', 'qfdate');
>
> then attaching the Rule to the date element:
>
> $form->addRule('weddingdate','Please enter a valid date', 'i ate');
> // 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
>
|
|
|
|
|