I have created a form with a select box in my view. In my controller is a rule for this select box: it is required. However, if non of the options in the select box are selected the form validates TRUE.
I noticed the same problem with check-boxes. If you choose ‘required’ as rule for a check box and the checkbox is not checked, the form wil validate true anyway. The user guide doesn’t mention this. Or did I miss the point?
The select box I used for testing looked like:
<select name=“aTab_Id” id=“Tab” size=“4”>
<option value=“2”>Option B</option>
<option value=“3”>Option C</option>
<option value=“1”>Option A</option>
</select>
And the accompanying rule in my controller looked like:
array(
‘field’ => ‘aTab_Id’,
‘label’ => ‘lang:post_aTab_Id’,
‘rules’ => ‘required’
),
[edit]
Mistake found: De CI Library Form_validation does allow and utilize the rule ‘required’ for check boxes and select boxes too. However, the extension of the Form_validation - which I use to validate file uploads too - caused the problem here. Happily that bug is solved, cause it is really a great extention which you can find here.