Set_select()不工作CodeIgniter [英] Set_select() not working on CodeIgniter
问题描述
我有一个选择框在我的形式,当我点击提交表单通过验证,如果一个错误发生,返回所有的值。这个工作期望我的选择框,我使用set_select,但它不工作数据进入数据库
I have a select box in my form and when I hit submit the form goes through validation and if an error happens, return all the value. This work expect for my select box, I have use the set_select but it doesnt work data comes in data base
<select name="leave_category_id" class="form-control" onchange="check_leave_category(this.value)" required >
<option value="" >Select Leave Category...</option>
<?php foreach ($all_leave_category as $v_category) :
?>
<option value="<?php echo $v_category->leave_category_id ?>" >
<?php echo set_select('leave_category_id',$cat); ?>
<?php echo $v_category->category ?> </option>
<?php endforeach;
?>
</select>
推荐答案
set_select()
函数打印<在适当的< option>
元素中的code> selected =selected但您的代码如下:
The set_select()
function prints out the selected="selected"
attribute in the <option>
element where appropriate. But your code is as follows:
<option value="<?php echo $v_category->leave_category_id ?>" >
^
closing the tag --> |
<?php echo set_select('leave_category_id',$cat); ?>
<?php echo $v_category->category ?>
</option>
所以当你看html时,它看起来像这样:
So when you look at the html, it will look something like this:
<option value="123">selected="selected" Category Name</option>
您的已选择
属性位于标记之外。我想你现在可以解决它;)
Got it? Your selected
attribute is placed outside the tag. I guess you'll be able to fix it now ;)
这篇关于Set_select()不工作CodeIgniter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!