在表单验证失败后重新填充Codeigniter中的复选框 [英] Repopulating checkboxes in Codeigniter after Unsuccessful Form Validation

查看:93
本文介绍了在表单验证失败后重新填充Codeigniter中的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在重新填充一组复选框后遇到问题,在表单验证失败后,用户将返回到相同的表单。下拉菜单和文本输入可以重新填充,但不能复选框!

I have a problem repopulating a set of checkboxes after an unsuccessful form validation returns the user back to the same form. Dropdown menus and text inputs could be repopulated, but not checkboxes!

以下是复选框的代码片段:

Here's a snippet of the code for the checkboxes:

        <td>
            <?php echo form_checkbox('ambience[]', 'casual', set_checkbox('ambience[]', 'casual')); ?> Casual <br />
            <?php echo form_checkbox('ambience[]', 'romantic', set_checkbox('ambience[]', 'romantic')); ?> Romantic <br />
            <?php echo form_checkbox('ambience[]', 'outdoor', set_checkbox('ambience[]')); ?> Outdoor / Alfresco <br />
            <?php echo form_checkbox('ambience[]', 'trendy', set_checkbox('ambience[]')); ?> Hip & Trendy <br />
            <?php echo form_checkbox('ambience[]', 'vibrant', set_checkbox('ambience[]')); ?> Vibrant <br />
            <?php echo form_checkbox('ambience[]', 'up_scale', set_checkbox('ambience[]')); ?> Upscale <br />
        </td>

成功重新填充的文本输入的代码段为:

The code snippet for text input which successfully repopulated is:

<?php echo form_dropdown('price_range', $options, set_value('price_range')); ?>

任何想法?我真的很困惑为什么 set_checkbox 不能正常工作。

Any ideas? I'm really confused why set_checkbox does not work as advertised.

推荐答案

set_checkbox 调用错误。当你在form_checkbox中使用像ambience []这样的数组时,你不想在 set_checkbox 调用中包含方括号([])。另一个问题是,set_checkbox需要第二个参数,你只包含在前两个复选框中。

You set_checkbox calls are wrong. When you're using an array like "ambience[]" in form_checkbox, you don't want to include the square brackets ([]) in your set_checkbox call. The other problem is that set_checkbox requires a second parameter which you've only included in the first 2 checkboxes.

set_checkbox应该总是这样:

The set_checkbox should always be like this:

set_checkbox('ambience', 'value');

其中'value'是 form_checkbox call。像这样:

Where 'value' is the second parameter of the form_checkbox call. Like this:

form_checkbox('ambience[]', 'value', set_checkbox('ambience', 'value'));

这篇关于在表单验证失败后重新填充Codeigniter中的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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