Reputation: 1743
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?
Upvotes: 0
Views: 3006
Reputation: 183
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
Upvotes: 1