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.
A:
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.
Chris Lively
2010-01-26 19:19:41
+1
A:
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')
}
antpaw
2010-01-26 19:24:10
Im using 2.3.4.
BDuelz
2010-01-26 19:25:29
So, how would I do that in my case...?
BDuelz
2010-01-26 19:26:27
updated, ($day === 'is ok') is only for demonstration. rewrite it so it will make sens to check the date
antpaw
2010-01-26 19:41:57
simple enough... thanks
BDuelz
2010-01-26 19:50:19