开发者

CodeIgniter: set_checkbox problem

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 – M开发者_JAVA技巧ERKEN<br />
</fieldset> 

It also has this validation rule in it:

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...


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.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜