0

我正在使用下面的行来检查我的添加用户表单以检查我的数据库中是否不存在电子邮件地址我感觉它工作正常但我无法收到任何错误消息。

$this->form_validation->set_rules('userEmail','E-Mail', 'required|valid_email|trim|max_length[99]|xss_clean|is_unique[users.email]');

在我看来我有<?php echo validation_errors(); ?>

我的控制器格式如下:

if($this->form_validation->run() === TRUE)
        {
            $userData = array(
                'fName' => $this->input->post('userFirstName', TRUE),
                'lName' => $this->input->post('userLastName', TRUE),
                'email' => $this->input->post('userEmail', TRUE),
                'password' => sha1($this->input->post('userPassword', TRUE))
            );  

            $this->db->escape($userData);
            $this->user_model->addUser($userData);
        }
4

3 回答 3

1

我将控制器更改为以下内容:

$this->form_validation->set_rules('userEmail','E-Mail', 'required|valid_email|trim|max_length[99]|xss_clean|is_unique[users.email]');
        $this->form_validation->set_rules('userPassword','Password', 'required|trim|max_length[99]|xss_clean');

        if($this->form_validation->run() === TRUE)
            {
                $userData = array(
                    'fName' => $this->input->post('userFirstName', TRUE),
                    'lName' => $this->input->post('userLastName', TRUE),
                    'email' => $this->input->post('userEmail', TRUE),
                    'password' => sha1($this->input->post('userPassword', TRUE))
                );  

                $this->db->escape($userData);
                $this->user_model->addUser($userData);
            }

            $data['contentMangement'] = $this->options_model->systemOptions();
            $data['pageTitle'] = 'Add User';
            $this->load->view('_assets/header', $data);
            $this->load->view('addUser', $data);
            $this->load->view('_assets/footer');
    }
于 2012-06-12T22:50:06.513 回答
0

只需使用 is_unique 预定义的验证规则。传递电子邮件列的表名和列名。

$this->form_validation->set_rules('userEmail','E-Mail', 'required|valid_email|trim|max_length[99]|xss_clean|is_unique[users.email]');
于 2012-06-12T06:30:31.123 回答
0

我们必须以 我的方式为 exp添加到is_unique的表名

array(
            'field' => 'email',
            'label' => 'email',
            'rules' => 'trim|required|valid_email|is_unique[users.email]',
            'errors' => array('required'  => 'Please enter a %s.','valid_email' => 'Please enter a valid %s.','is_unique' => 'email already exist.')
        ),

希望你能理解。

于 2016-08-17T12:00:09.817 回答