如何使用3个选择菜单(PHP和Kohana)验证“出生日期”?

如何使用3个选择菜单(PHP和Kohana)验证“出生日期”?

问题描述:

Using the Kohana framework, how would you validate a date of birth given 3 separate drop downs? If an error occurs, only one error should show.

使用Kohana框架,如何在3个单独的下拉菜单中验证出生日期? 如果发生错误,则只应显示一个错误。 p> div>

you can setup additional custom prefilters and callbacks http://docs.kohanaphp.com/libraries/validation http://docs.kohanaphp.com/libraries/validation are you using ko3 or ko2?

<?
  // somewhere in your controller
$form = $_POST;
$form['b_day'] = $form['year'].'-'.$form['month'].'-'.$form['day'];
unset($form['year'], $form['month'], $form['day']);
$orm->validate($form);

// somewhere in your model
public function validate(array & $array, $save = FALSE)
{
    $array = Validation::factory($array)
        ->pre_filter('trim')
        ->add_rules('b_day', array($this, 'is_good_date'))
        ;

    return parent::validate($array, $save);
}

private function is_good_date($day)
{
    return (bool) ($day === 'is ok')
}

Without knowing the Kohana framework, I would probably not validate the first two drop downs, only the third which would take all of the values into consideration.