【发布时间】:2011-12-05 08:05:53
【问题描述】:
我的 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>
我在我的控制器中设置了一个验证规则(在我看来)确保选中了一个复选框,
$this->form_validation->set_rules('age[]', 'age group', 'required|trim');
但是,在测试这个时,我收到一条名为 age[] 的复选框的错误消息,我只想检查 age[] 是否为空。
我怎样才能做到这一点?
【问题讨论】:
标签: php forms codeigniter checkbox validation