How to validate a "date of birth" using 3 select menu's (PHP & Kohana)?
Using开发者_如何学C 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.
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.
精彩评论