Php codeigniter表单验证和数组作为字段名

Php codeigniter表单验证和数组作为字段名,php,forms,codeigniter,checkbox,validation,Php,Forms,Codeigniter,Checkbox,Validation,我的HTML中有一组复选框,如下所示 div class="grid_7"> <fieldset class="age shadow_50"> <label class="legend">Age Group</label> <div class="formRow checkbox"> <

我的HTML中有一组复选框,如下所示

div class="grid_7">
                    <fieldset class="age shadow_50">
                        <label class="legend">Age Group</label>
                            <div class="formRow checkbox">
    <input id="" type="checkbox" name="age[]" value="child" />
    <label>Child</label>
</div>

                            <div class="formRow checkbox">
    <input id="" type="checkbox" name="age[]" value="30's" />
    <label>30s</label>
</div>
                            <div class="formRow checkbox">
    <input id="" type="checkbox" name="age[]" value="60's" />
    <label>60's</label>
</div>

                            <div class="formRow checkbox">
    <input id="" type="checkbox" name="age[]" value="teen" />
    <label>Teen</label>
</div>
                            <div class="formRow checkbox">
    <input id="" type="checkbox" name="age[]" value="40's" />
    <label>40's</label>
</div>

                            <div class="formRow checkbox">
    <input id="" type="checkbox" name="age[]" value="70's" />
    <label>70's</label>
</div>
                            <div class="formRow checkbox">
    <input id="" type="checkbox" name="age[]" value="20's" />
    <label>20's</label>
</div>

                            <div class="formRow checkbox">
    <input id="" type="checkbox" name="age[]" value="50's" />
    <label>50's</label>
</div>
                    </fieldset>
                </div>
然而,当测试这个时,我会收到一个名为age[]的错误消息,我只想检查age[]是否为空


我怎样才能做到这一点呢?

你不能像那样测试
age[]
,它是一个数组。有几种方法可以做到这一点,但您所做的
required
不是其中之一

您可以使用javascript或通过自己的自定义方法运行
age[]

在CI中使用数组的详细信息如下:


如果您使用javascript路径,您可以使用jQuery来迭代您的复选框(使用类链接它们),并确保选中其中一个复选框。

老问题,但对于任何努力做到这一点的人,我相信您可以通过在
age
而不是
age[]
上设置规则来做到这一点

$this->form_validation->set_rules('age', 'age group', 'fnName');
$this->form_validation->set_rules('age', 'age group', 'fnName');