[英]Grocery-CRUD and form validation
I'm using grocery crud and need to validate form fields. 我正在使用杂货杂货,需要验证表单字段。 Following is code from
Controller
... 以下是
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. 我认为杂货店中的set_rules仅使用类型数据验证输入字段。
$crud->set_rules([fieldDB],[label],[type data]);
please check this http://www.grocerycrud.com/examples/set_validation_rules 请检查此http://www.grocerycrud.com/examples/set_validation_rules
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.