dtf1111 2017-07-01 09:02
浏览 109

ci中的表单验证复选框不起作用

i have form with check box and inputbox but validation check box when checked boxes not worked and show validation error

Post controller:

$this->load->helper('form');
$this->load->library('form_validation');
$rules=array(
    array(
        'field'=>'title',
        'label'=>'Title',
        'rules'=>'required'),
    array('field'=>'content',
        'label'=>'Content',
        'rules'=>'required'),
    array('field'=>'category',
        'label'=>'category',
        'rules'=>'required'));


$this->form_validation->set_rules($rules);

Index view:

<div class="box-content">
    <h3>category</h3>
    <?php 
        $pcat=isset($post_cat)?$post_cat:array();
        foreach($category as $key => $value){
            $checked=in_array($value['category_id'],$pcat);
            $name='category['.$value['name'].']';
            echo '<label style="display:block;">';
            echo $value['name'];
            echo form_checkbox(
            array(
            'name'=>$name,
            'value'=>$value['category_id'],
            'checked'=>$checked));}
            echo '</label>';
    ?>
    <?php  echo form_error('category');?>
</div>

please help me for solve that

  • 写回答

1条回答 默认 最新

  • douqiao5543 2017-07-01 09:46
    关注

    As your category input is array. You need to validate using array to. Change this in your controller:

     array('field'=>'category[]',
                'label'=>'category',
                'rules'=>'required'));
    
    评论

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办