[英]set_select() not working in codeigniter framework
I want the select box show the same value before the from submit after the redirection in this code $cat value come to the session i am not using validation rule for select box i want only the select box not change after the redirection Select Leave Category... leave_category_id ?>" 我希望选择框在此代码$ cat值中的重定向之后的提交之后显示从提交之前的相同值,我不对选择框使用验证规则,我希望仅选择框在重定向后不更改选择“离开类别”。 .. Leave_category_id?>“
<?php echo set_select('leave_category_id', $cat, true); ?>> <?php echo $v_category->category ?> </option>
<?php endforeach;
?>
</select>
Try 尝试
<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>
There are two things to keep in mind: First you have to use the validation class to be able to use the set_select()
function. 有两件事要牢记:首先,您必须使用验证类才能使用
set_select()
函数。 Second you have to pass the database information to that function, like this: 其次,您必须将数据库信息传递给该函数,如下所示:
<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>
If $model->selection
is two
, then the second option will be selected in the example above. 如果
$model->selection
为two
,则在上面的示例中将选择第二个选项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.