CodeIgniter自定义错误消息不起作用?

时间:2016-03-16 18:14:50

标签: php codeigniter

我已阅读文档,但此表单仍显示默认消息?

据我所知,我正在制定规则,然后将消息应用于该规则?

  

{{3}}

$this->load->library('form_validation');
    $this->form_validation->set_error_delimiters('<p class="text-danger"><i class="fa fa-exclamation-triangle"></i> ', '</p>'); //Controls what element the error is put in, <p> by default.//
    $this->form_validation->set_rules('Username', 'Username', 'trim|required');
    $this->form_validation->set_message('Username', 'username required');
    $this->form_validation->set_rules('Password', 'Password', 'trim|required|callback_CheckDatabase');
    $this->form_validation->set_message('Password', 'password required');

1 个答案:

答案 0 :(得分:0)

  

如果您需要为特定字段设置自定义错误消息   一些特殊的规则,使用set_rules()方法:

$this->form_validation->set_rules('field_name', 'Field Label', 'rule1|rule2|rule3',
    array('rule2' => 'Error Message on rule2 for this field_name')
);

您使用的是旧文档。 Documentation