Grocery-CRUD和表格验证

时间:2014-05-26 14:52:11

标签: php codeigniter validation grocery-crud

我使用杂货店crud并需要验证表单字段。以下是Controller ...

的代码
    $crud = new grocery_CRUD();
    $this->config->set_item('grocery_crud_file_upload_allow_file_types','gif|jpeg|jpg|png');
    /*set theme and table*/
    //$crud->set_theme('datatables');
    $crud->set_subject('Company');
    $crud->set_table('company');

    /*column in displayed table and fields to view/add/edit */
    $crud->columns('Id','Name','Email','Address');
    $crud->fields('Name','Description','Email','Address');

    /*required field in add/edit*/
    $crud->required_fields('Name','Address');
    //$crud->set_field_upload('Logo','images');

    /*form validation rules*/
    $crud->set_rules('name', 'Name', 'trim|max_length[50]|required|is_unique[company.name]');
    $crud->set_rules('description', 'Description', 'trim|max_length[255]');
    $crud->set_rules('email', 'Email', 'trim|valid_email|max_length[255]|is_unique[company.email]');
    $crud->set_rules('address', 'Address', 'trim|required|max_length[255]');

    /* $cols = $crud->getColumns();
    foreach ($cols as $col){
        $crud->callback_column($col,array($this,'_column_center_align'));
    } */
    $output = $crud->render();

    $this->load->view('admin/view/company',$output);

但我可以看到,当我编辑或添加新记录时,表单验证没有发生。

有谁可以告诉我哪里出错?

1 个答案:

答案 0 :(得分:1)

我认为杂货店中的set_rules只验证带有类型数据的输入字段。

$crud->set_rules([fieldDB],[label],[type data]);

请查看此http://www.grocerycrud.com/examples/set_validation_rules