I'm using Codeigniter 3.
The countries select box is an optional field on a form:
<select name="countries">
<option>Choose a Country</option>
<option value="en">England</option>
<option value="fr">France</option>
<option value="de">Germany</option>
</select>
I have the following line for the countries field validation:
$this->form_validation->set_rules('year', 'Year', 'trim|integer');
When I submit the form with the 1st option (Choose a Country), even without a value defined the validator sees something like this:
echo '<pre>';
print_r($this->input->post('year'));
echo '</pre>';
>> Choose a Country
.. when I am expecting something like false or null.
How can I make CI ignore the value when there isn't one selected?
Thanks in advance!
答案 0 :(得分:0)
首先,您粘贴错误的行,我认为它应该是cbIniValues
而不是countries
。
你可以通过以下方式实现:
year
none
<select name="countries">
<option value="none">Choose a Country</option>
<option value="en">England</option>
<option value="fr">France</option>
<option value="de">Germany</option>
</select>