复选框权限[访问]验证不工作Codeigniter

时间:2015-02-23 06:42:31

标签: php codeigniter

我正在设置一些复选框,复选框上的名称为name="permission[access][]"

我无法使用codeigniter验证,因为它不会显示验证错误消息

如何使用名称 name="permission[access][]"

控制器:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Post_test extends MX_Controller {

public function index() {

    $data['action'] = site_url('post_test');

    $ignore = array(
        'common/dashboard',
        'common/footer',
        'common/header'
    );

    $data['permissions'] = array();

    $files = glob(APPPATH . 'controllers/*/*.php');

    foreach ($files as $file) {
        $part = explode('/', dirname($file));

        $permission = end($part) . '/' . basename($file, '.php');

        if (!in_array($permission, $ignore)) {
            $data['permissions'][] = $permission;
        }
    }

    if ($this->input->post('permission[access]') !== FALSE) {
        $data['access'] = $this->input->post('permission[access]');
    } else {
        $data['access'] = array();
    }

    $this->load->library('form_validation');

    $this->form_validation->set_rules('permission[access]', 'Permission Access', 'required');

    if ($this->form_validation->run() == false) {

    $this->load->view('post_test.tpl', $data);

    } else {

        var_dump($_POST);

    }
}

}

查看:

<?php echo validation_errors('<div class="alert alert-danger">', '</div>'); ?>
<form action="<?php echo $action;?>" method="post" enctype="multipart/form-data" class="form-horizontal">
<fieldset>
<div class="form-group">
<label class="col-sm-2 control-label"></label>
<div class="col-sm-10">
<div class="well well-sm" style="height: 150px; overflow: auto;">
<?php foreach ($permissions as $permission) { ?>
<div class="checkbox">
<label>
<?php if (in_array($permission, $access)) { ?>
<input type="checkbox" name="permission[access][]" value="<?php echo $permission; ?>" checked="checked" />
<?php echo $permission; ?>
<?php } else { ?>
<input type="checkbox" name="permission[access][]" value="<?php echo $permission; ?>" />
<?php echo $permission; ?>
<?php } ?>
</label>
</div>
<?php } ?>
</div>
</div>
</fieldset>
<div class="buttons clearfix">
<div class="pull-left"></div>
<div class="pull-right">
<br/>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>

0 个答案:

没有答案