如果在Codeigniter中的编辑表单中验证失败,则重新填充复选框 [英] Re-populate checkbox if it fails in validation in an edit form in Codeigniter
问题描述
我在codeigintier中的数据编辑表单上工作。并且问题是关于重新填充复选框
I works on the an data-edit form in codeigintier. And the problem is about re-populate checkbox
如果它是一个添加表单(这意味着我不需要关心数据库中的值):
It works if it is an add form (that means I need not concern about the value in database):
<?= set_checkbox('is_default', '1'); ?> for checkbox
问题是,在编辑表单中:
The problem is, in the edit form:
我无法重新填充复选框
<?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
我已经在控制器中设置验证规则,添加表单中的代码正在工作,但是如何处理编辑表单的情况? p>
I have already set the validation rule in controller, the code in the add form is working , but how to handle the case for edit form?
推荐答案
set_checkbox使用第三个参数设置默认状态,所以基本上你必须这样做
set_checkbox takes a third argument to set the default state, so basically you have to do something like this
echo set_checkbox('is_default', 1, $customer_group[0]['is_default'] == "1");
这篇关于如果在Codeigniter中的编辑表单中验证失败,则重新填充复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!