CodeIgniter:set_checkbox问题 [英] CodeIgniter: set_checkbox problem

查看:166
本文介绍了CodeIgniter:set_checkbox问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎遇到了非常讨厌的问题:

I seem to be running into something really nasty:

我有一个包含一组复选框的表单。
我已经为我的表单设置了验证规则,并为我的复选框组添加了一个空的
。但是,在验证我的表单并给出错误后,
它仅重新检查所选组中的最后一个。这只是
驱动我坚果,因为用户永远不会注意到它是未经检查!

I have a form which contains a group of checkboxes. I have set up validation rules for my form, and just added an empty one for my checkbox group. However, after validating my form and giving an error, it only rechecks the last one in the group that was selected. This is just driving me nuts, since the user will never notice it was unchecked!

现在,在构建系统之前,我刚刚硬编码的形式以检查它是否工作
我如何希望它工作。

for now, before building up the system, I just hardcoded the form to check if it works how I want it to work.

<fieldset>
    <legend>Locaties veldwedstrijden</legend>
    <?php echo form_checkbox('locatie','oudenaarde', set_checkbox('locatie','oudenaarde'));?>3-7-2011 te Oudenaarde <br />
    <?php echo form_checkbox('locatie','arendonk', set_checkbox('locatie','arendonk'));?>31-7-2011 Arendonk<br />
    <?php echo form_checkbox('locatie','westdonk', set_checkbox('locatie','westdonk'));?>11-09-2011 Westhoek – MERKEN<br />
</fieldset> 

它也有这个验证规则:

array('field' => 'locatie','label' => '','rules' => ''),

有人可以告诉我我做错了什么?我读了整个手册,但我不能
发现这个代码可能有错误的一点提示...

Can anybody tell me what I'm doing wrong? I read the whole manual, but I can't find the slightest hint of what might be wrong with this code...

推荐答案

您正在使用复选框,如单选按钮。无论有多少选中复选框,它们都被命名为locatie,php只会看到一个值。

You're using a checkbox like a radio button. No matter how many checked checkbox, they're all named locatie, php will only see one value.

如果你想保存多个值,需要为每个复选框(locatie1,locatie2,locatie3)使用不同的名称或使用php样式名称数组(locatie [])。我不确定后者,CI表单助手函数将正常工作与该风格的命名虽然。

If you wanted to save multiple values from the checkbox, you'd either need to use a different name for each checkbox (locatie1, locatie2, locatie3) or use a php style name array (locatie[]). I'm not sure for the latter that the CI form helper function will work properly with that style of naming though.

这篇关于CodeIgniter:set_checkbox问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆