当前位置:  开发笔记 > 编程语言 > 正文

在CodeIgniter中确认密码

如何解决《在CodeIgniter中确认密码》经验,为你挑选了1个好方法。

我正在使用CodeIgniter 3.1.3构建一个博客,我在管理员中有一个功能来添加新用户.当我尝试添加新用户时,我收到以下错误:

密码字段与confirm_password字段不匹配.

虽然密码和confrom密码字段中的给定密码是相同的.

我无法弄清楚导致问题的原因.

这是我的模型:

public function insert($data){
    $this->db->insert('users', $data);
    return true;
}

这是我的控制器

public function add(){
        //Validation Rules
        $this->form_validation->set_rules('first_name','First Name','trim|required');
        $this->form_validation->set_rules('last_name','Last Name','trim|required');
        $this->form_validation->set_rules('email','Email','trim|required|valid_email');
        $this->form_validation->set_rules('username','Username','trim|required|min_length[3]');
        $this->form_validation->set_rules('password', 'Password', 'required|matches[confirm_password]');

        $data['groups'] = $this->User_model->get_groups();

        if($this->form_validation->run() == FALSE){
            //Views
            $data['main_content'] = 'admin/users/add';
            $this->load->view('admin/layouts/main', $data);
        } else {
            //Create Data Array
            $data = array(
                'first_name'    => $this->input->post('first_name'),
                'last_name'     => $this->input->post('last_name'),
                'username'      => $this->input->post('username'),
                'password'      => md5($this->input->post('password')),
                'group_id'      => $this->input->post('group'),
                'email'         => $this->input->post('email')
            );

            //Table Insert
            $this->User_model->insert($data);

            //Create Message
            $this->session->set_flashdata('user_saved', 'User has been saved');

            //Redirect to pages
            redirect('admin/users');
        }

这是我的观点:

Geordy James.. 25

$this->form_validation->set_rules('first_name','First Name','trim|required');
$this->form_validation->set_rules('last_name','Last Name','trim|required');
$this->form_validation->set_rules('email','Email','trim|required|valid_email');
$this->form_validation->set_rules('username','Username','trim|required|min_length[3]');
$this->form_validation->set_rules('password', 'Password', 'required');
$this->form_validation->set_rules('confirm_password', 'Confirm Password', 'required|matches[password]');

将表单验证更改为此,并记住在config/autoload.php文件中自动加载表单验证$autoload['libraries'] = array('form_validation');.如果它不起作用,请在下面评论.



1> Geordy James..:
$this->form_validation->set_rules('first_name','First Name','trim|required');
$this->form_validation->set_rules('last_name','Last Name','trim|required');
$this->form_validation->set_rules('email','Email','trim|required|valid_email');
$this->form_validation->set_rules('username','Username','trim|required|min_length[3]');
$this->form_validation->set_rules('password', 'Password', 'required');
$this->form_validation->set_rules('confirm_password', 'Confirm Password', 'required|matches[password]');

将表单验证更改为此,并记住在config/autoload.php文件中自动加载表单验证$autoload['libraries'] = array('form_validation');.如果它不起作用,请在下面评论.

推荐阅读
重庆制造漫画社
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有