在表单验证中,当前密码必须与我登录的密码匹配。如果我引入的当前密码与我用于登录的密码匹配,我可以更改它。但它不起作用,我可以在我当前的密码字段中输入任何密码。我的问题是如何在匹配函数中输入我用来登录的密码。(我用来记录的密码存储在会话中)。
function edit_info()
{
$this->load->helper(array('form', 'url'));
$this->load->library('session');
$this->load->library('form_validation');
$this->form_validation->set_rules('firstname2','FirstName','trim|required');
$this->form_validation->set_rules('lastname2','LastName','trim|required');
$this->form_validation->set_rules('current_password','Current Password','trim|required|matches(password)');
$this->form_validation->set_rules('password3','Password','trim|required|min_length[4]|max_length[32]');
if($this->form_validation->run() == FALSE)
{
$this->edit();
}
else
{
$this->load->model('membership_model');
if($this->membership_model->edit_member())
{
$data['main_content']='edit_successful';
$this->load->view('includes/template',$data);
}
else
{
$this->load->view('main_menu');
}
}
}
答案 0 :(得分:0)
您需要对控制器内的函数进行回调。
// call function to check
$this->form_validation->set_rules('current_password','Current Password','trim|required|callback_password_check');
// do your check and return false or true
public function password_check($str){
}
转到:http://ellislab.com/codeigniter%20/user-guide/libraries/form_validation.html#callbacks