这会将条目标记为“已选择”,因为...默认情况下已选择。您想要一个多选下拉菜单,对吗?
<select name="schoolGroups[]" multiple="multiple">
<option value="0" selected="selected">Select User Group</option>
<option value="1">Admin</option>
</select>
至于验证,您可能想建立自己的验证规则:
你的控制器的方法:
//...
$this->form_validation->set_rules('schoolGroups','School groups','required|callback_check_default');
$this->form_validation->set_message('check_default', 'You need to select something other than the default');
//...
添加这个其他方法:
function check_default($array)
{
foreach($array as $element)
{
if($element == '0')
{
return FALSE;
}
}
return TRUE;
}
如果您只想要单选(那么无法进行多选),那就更简单了:
html:
<select name="schoolGroups">
<option value="0" selected="selected">Select User Group</option>
<option value="1">Admin</option>
</select>
验证方法:
$this->form_validation->set_rules('schoolGroups','School groups','required|callback_check_default');
$this->form_validation->set_message('check_default', 'You need to select something other than the default');
回调:
function check_default($post_string)
{
return $post_string == '0' ? FALSE : TRUE;
}