Reputation: 630
What is the simplest (cleaner) way to validate optional fields using Kohana 3.2 ORM?
Upvotes: 0
Views: 415
Reputation: 630
Well, maybe (:P) I've forgot the differences between mandatory fields and optional fields:
'city' => array(
array('not_empty'),
array('min_length', array(':value', 3)),
array('max_length', array(':value', 255)),
),
'longitude' => array(
array('is_coordinate'),
)
The second one, the optional field 'longitude' is only triggered if has something that is not accepted by Valid::is_coordinate.
The first one, the mandatory field, is controlled by 'not_empty', or something with similar behavior.
About the filter, ORM filters are processed before the rules, so something like this is enough:
public function filters() {
return array(
'longitude' => array(array('trim'))
);
}
I'm tested myself right now, and is working nicely.
Upvotes: 2