如何使用Codeigniter以编辑形式重新填充复选框 [英] How to re-populate check box in edit form using Codeigniter
问题描述
到目前为止,我知道如何重新填充表单输入和复选框。
它看起来像这样:
value =<?= set_value('rank')?>输入
和
<?= set_checkbox('is_default','1'); ?>对于复选框
问题是,在编辑表单中如何:
输入值是sofar ok:
value =<?= set_value ,$ customer_group [0] ['rank']);?>
但我无法重新填写复选框
<?php if($ customer_group [0] ['is_default'] ==1)echochecked set_checkbox('is_default','1'); ?>
复选框将检查,即使我没有检查它在编辑=>未能验证的形式,感谢帮助
更改为:
<?php
if(isset($ _ POST ['is_default'])|| $ customer_group [0 ] ['is_default'] ==1){
echochecked;
}
set_checkbox('is_default','1');
?>
失败
<?php
if(isset($ _ POST ['is_default'])){
echochecked; set_checkbox('is_default','1');
} elseif($ customer_group [0] ['is_default'] ==1){
echochecked; set_checkbox('is_default','1');
}
?>
所以如果用户选中复选框并且验证失败,表单将有一个选中的复选框,如果没有帖子数据,那么将由 $ customer_group
中的数据库数据检查
So far I know how to repopulate the form input and checkbox
It looks like that:
value="<?= set_value('rank') ?>" for input
and
<?= set_checkbox('is_default', '1'); ?> for checkbox
The problem is, how about in the edit form:
The input value is sofar ok:
value="<?= set_value('rank',$customer_group[0]['rank']); ?>"
but I can't repopulate the checkbox
<?php if ($customer_group[0]['is_default'] == "1") echo "checked"; set_checkbox('is_default', '1'); ?>
The checkbox will check even I have not check it in the edit => fail to validate in the form, thanks for helping
Update:
Is it correct if change to :
<?php
if(isset($_POST['is_default']) || $customer_group[0]['is_default'] == "1"){
echo "checked";
}
set_checkbox('is_default', '1');
?>
A simple one just check for post data too if validation fails
<?php
if(isset($_POST['is_default'])){
echo "checked"; set_checkbox('is_default', '1');
}elseif ($customer_group[0]['is_default'] == "1"){
echo "checked"; set_checkbox('is_default', '1');
}
?>
So if user checks checkbox and validation fails the form will have a checked check box as to save the choice made by user if there is no post data then it will be checked by database data that is in $customer_group
这篇关于如何使用Codeigniter以编辑形式重新填充复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!