我希望选择框在提交之前显示相同的值,在此代码中重定向后,$ cat值进入会话我没有使用选择框的验证规则我希望只有选择框在重定向后不会更改 选择离开类别... leave_category_id?>"
<?php echo set_select('leave_category_id', $cat, true); ?>> <?php echo $v_category->category ?> </option>
<?php endforeach;
?>
</select>
答案 0 :(得分:0)
尝试
<select name="leave_category_id" class="form-control" onchange="check_leave_category(this.value)" required >
<option>Select Leave Category...</option>
<?php foreach ($all_leave_category as $v_category) :
// Using short tag
//$v_category->leave_category_id == $cat ? $selected = 'selected' : $selected = '';
// without using short tag
if($v_category->leave_category_id == $cat) $selected = 'selected'; else $selected = '';
?>
<option value="<?php echo $v_category->leave_category_id ?>" <?php echo $selected?> > <?php echo $v_category->category ?> </option>
<?php endforeach;
?>
</select>
答案 1 :(得分:0)
要记住两件事:首先,您必须使用验证类才能使用<select name="myselect">
<option value="one" <?php echo set_select('myselect', 'one', ($model->selection == 'one')); ?> >One</option>
<option value="two" <?php echo set_select('myselect', 'two', ($model->selection == 'two')); ?> >Two</option>
<option value="three" <?php echo set_select('myselect', 'three', ($model->selection == 'three')); ?> >Three</option>
</select>
函数。其次,您必须将数据库信息传递给该函数,如下所示:
$model->selection
如果two
为{{1}},则会在上面的示例中选择第二个选项。
请参阅link