I’m trying to setup the registration function on my site and I need to validate user’s input of country of select type:
public function rules()
{
return array(
......
'country' => array(
array('not_empty'),
array('digit'),
array(array($this, 'country_from_list'), array(':validation', ':field'))
),
......
);
}
and here is my callback:
public static function country_from_list($values)
{
// array id => value
$countries = ORM::factory('country')->getActive('array');
return Validation::factory($values)
->rule('country', 'in_array', array(':value', $countries));
}
but it doesn’t work. Any ideas? I’m trying to port it from Kohana 3.0.9…
If you’re passing the Validation object to the callback method, you can do a custom error on it if it fails your condition. (inside of your callback: $validation->error(…))
Otherwise, your callback should accept the field’s value, return bool and look like this :
And the method: