douhui1630 2014-05-26 14:52
浏览 27

Grocery-CRUD和表格验证

I'm using grocery crud and need to validate form fields. Following is code from 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);

But I can see that the form validation is not happening when I edit or add new record.

Can anybody tell where am I going wrong?

  • 写回答

1条回答 默认 最新

  • dou31797719 2015-02-13 11:12
    关注

    i think set_rules in grocery only validates input field with type data.

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

    please check this http://www.grocerycrud.com/examples/set_validation_rules

    评论

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?