tags:

views:

73

answers:

2

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
+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
Im using 2.3.4.
BDuelz
So, how would I do that in my case...?
BDuelz
updated, ($day === 'is ok') is only for demonstration. rewrite it so it will make sens to check the date
antpaw
simple enough... thanks
BDuelz