2016-03-16 65 views
0

我已閱讀文檔,但此表單仍顯示默認消息?CodeIgniter自定義錯誤消息不起作用?

據我所知,我設置了一個規則,然後將消息應用於該規則?

https://ellislab.com/codeigniter/user-guide/libraries/form_validation.html

$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'); 

回答

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