[英]GroceryCrud validation custom messages
I have one question.. How to validate fields data with custom error messages? 我有一个问题。如何使用自定义错误消息验证字段数据? I use codeigniter, and grocery crud with twitter bootstrap theme, and do some field required, for example:
我使用codeigniter和杂物杂货作为Twitter引导主题,并做一些必填字段,例如:
$crud->set_rules('first_name', 'NAME', 'required'); OR $crud->required_fields('first_name');
Validation work fine, but if validation unsuccessfull - we see just alert with standart message - "An error has occurred on insert\\update". 验证工作正常,但是如果验证不成功-我们只会看到带有标准消息的警报-“ insert \\ update发生错误”。 How to display custom message that field are required or etc. ?
如何显示必填字段等的自定义消息? Thanks.
谢谢。
Although this is old topic, but i thing someone can get this error as me just get it. 尽管这是个老话题,但是我觉得有人可以得到这个错误。
We can't use CI set_message function for CroceryCrud validation. 我们不能将CI set_message函数用于CroceryCrud验证。 Because CroceryCrud use its validation object.
因为CroceryCrud使用其验证对象。
You can edit libraries/Grocery_CRUD.php, find line "protected function form_validation()", 您可以编辑库/Grocery_CRUD.php,找到“受保护的函数form_validation()”行,
at under this function, you can copy it, rename and edit access modifiler to public : 在此功能下,您可以将其复制,重命名并编辑访问修饰符以公开:
public function get_form_validation(){
if($this->form_validation === null)
{
$this->form_validation = new grocery_CRUD_Form_validation();
$ci = &get_instance();
$ci->load->library('form_validation');
$ci->form_validation = $this->form_validation;
}
return $this->form_validation;
}
Now, you can call it in your controller : 现在,您可以在控制器中调用它:
$crud-> get_form_validation()->set_message('check_city',"invail %s");
Take a look at function set_message
in form_validation
library: 看看功能
set_message
在form_validation
库:
http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html#settingerrors http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html#settingerrors
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.