quickform - checking a valid date rule for a date element

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

quickform - checking a valid date rule for a date element

luke BAKING barker
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
                                                           
--

~L~

[hidden email]
http://www.battez.org
---------------------------------------
I'm doggone gonna be with
Some real people...

(  R & E )

--
PEAR General Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply | Threaded
Open this post in threaded view
|

Re: quickform - checking a valid date rule for a date element

Laurent Laville
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
>    

--
PEAR General Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php