kohana

Kohana 3 form select validation


Hay all, I am trying to validate a select in kohana 3.0 and I am using the necessary rules. However the validation does no "kick in" when the user does not make a selection.

<select id="discipline" name="discipline" >
<option value="0"> -- Select One -- </option>
<option value="-2">Information Technology and Engineering</option>
<option value="4">Business and Training Seminars</option>
</select>

That was my select, now i have applied these rules to the post array before i check for validation errors.

$post = Validate::factory($_POST)
                ->rule('discipline', 'not_empty')
                ->rule('discipline', 'numeric');

When I submit the form without making a selection, the form submits and the rules should stop it.

Any ideas ?


Solution

  • Your still putting a value for the first one, as 0. Leave the value as value="". 0 is numeric and considered not empty.