Re: Quickform date comparison
| From: | email_fb-ml at yahoo dot fr | Date: | Thu, 01 Dec 2005 12:15:03 +0000 |
| Subject: | Re: Quickform date comparison | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-22122@lists.php.net to get a copy of this message | ||
Thanks for your suggestion but I have used a addRule :
$form->addRule(array('date_debut_session',
'date_fin_session'), 'Pb de date', 'compare',
array('lt','date','dMYHi'), 'server');
and modified the validatefunction
HTML\QuickForm\Rule\Compare.php as below :
function validate($values, $operator = null)
{
$type=$operator[1];
$additionalTypeInfo=$operator[2];
$operatorType=getType($operator);
$operator=$operator[0];
if ($operatorType=='array') {
if ($type=='date') {
if($additionalTypeInfo=='dMYHi') {
$startDate =
$values[0]['Y']."-".$values[0]['M']."-".$values[0]['d']."
".$values[0]['H'].":".$values[0]['i'].":00";
$endDate =
$values[1]['Y']."-".$values[1]['M']."-".$values[1]['d']."
".$values[1]['H'].":".$values[1]['i'].":00";
$values[0] = strtotime($startDate);
$values[1] = strtotime($endDate);
} else {
// unsupported date comparison
return false;
}
} else {
// unsupported type comparison
return false;
}
}
$operator = $this->_findOperator($operator);
if ('==' != $operator && '!=' != $operator) {
$compareFn = create_function('$a, $b',
'return floatval($a) ' . $operator . '
floatval($b);');
} else {
$compareFn = create_function('$a, $b',
'return $a ' . $operator . ' $b;');
}
return $compareFn($values[0], $values[1]);
}
--- Justin Patrin <papercrane@gmail.com> a écrit :
> On 11/30/05, email_fb-ml@yahoo.fr
> <email_fb-ml@yahoo.fr> wrote:
> > Hi all,
> > I would like to compare two date elements with
> > quickform but I didn't find how to do that in the
> > documentation, I need to test if
> $date_debut_session >
> > $date_fin_session
> > Is it possible with quickform ?
> > Thanks in advance for your help.
> > Fred
> >
> > $options = array(
> > 'language' => 'fr',
> > 'format' => 'dMYHi',
> > 'minYear' => 2005,
> > 'maxYear' => 2012
> > );
> >
> > $date_debut_session = &
> $form->addElement('date',
> > 'date_debut_session', _SESSIONDATEDEB, $options);
> > if
> (!isset($value[0]['date_debut_session'])) {
> >
> $date_debut_session->setValue(date("Y-m-d"));
> > } else {
> >
> >
>
$date_debut_session->setValue($value[0]['date_debut_session']);
> >
> > }
> >
> > $date_fin_session = &
> $form->addElement('date',
> > 'date_fin_session', _SESSIONDATEFIN, $options);
> > if (!isset($value[0]['date_fin_session']))
> {
> >
> $date_fin_session->setValue(date("Y-m-d"));
> > } else {
> >
> >
>
$date_fin_session->setValue($value[0]['date_fin_session']);
> >
> > }
> >
>
>
> I suggets using a form rule (addFormRule) and the
> Date package.
>
> --
> Justin Patrin
>
___________________________________________________________________________
Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger
Téléchargez cette version sur http://fr.messenger.yahoo.com