2012-09-25 15 views
0

這是什麼怪事,當set_rules被告知尋找current_password它不會工作,當它被告知尋找current-password它。set_rules()不合作

<input type="password" name="current_password" id="current_password" value=""/> 

請注意,name和id都有下劃線。

$this->form_validation->set_rules('current_password', 'Password', 'required|callback_check_password['.$user_id.']'); 
//This gives me 
Unable to access an error message corresponding to your field name. 

以上規則不會工作,但如果我改變它太set_rules('current-password'它開始顯示錯誤消息。

<?php echo validation_errors(); ?>

做後期的轉儲印刷錯誤信息顯示array(1) { ["current_password"]=> string(4) "test" }

+0

我不知道,如果回調格式不錯,我認爲它應該是'callback_check_password'而不是'callback_check_password ['。$ user_id。']' – manix

+0

我正在傳遞另一個參數,它是允許的。 – Bankzilla

+0

如何在回調函數中設置字段消息? – manix

回答

0

我是不是在回調函數設置的錯誤消息

function check_password($password, $user_id){ 
    $check = $this->Usermodel->check_password($password, $user_id); 
    if($check){ 
     return TRUE; 
    } else { 
     $this->form_validation->set_message('check_password', 'Incorrect password'); 
     return FALSE; 
    } 
}