set_rules()不合作

时间:2012-09-25 22:20:07

标签: php codeigniter validation

这很糟糕,当set_rules被告知寻找current_password时,它被告知寻找它current-password时它不起作用。

<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" }

1 个答案:

答案 0 :(得分: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;
    }
}