简体   繁体   中英

Grocery-CRUD and form validation

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM