我正在尝试添加自定义错误消息以进行代码验证器表单验证。
$this->load->library('form_validation');
$this->form_validation->set_rules('month', 'Month', 'trim|required', array('required' => 'You need to supply period starting month'));
但不幸的是,我仍然得到
“月”字段为必填项。
错误消息。
我的ci版本是 2.0.2
答案 0 :(得分:0)
在CI 2中,您需要设置自定义错误消息,如下所示:
$this->form_validation->set_message('rule', 'Error Message');
根据您的要求,这可能会起作用,
$this->form_validation->set_rules('month', 'period starting month', 'trim|required');
$this->form_validation->set_message('required', 'You need to supply %s');
请参阅Docs
set_rules
不会未在您使用的版本中设置验证消息。