【问题标题】:Unique email address validation唯一电子邮件地址验证
【发布时间】:2014-05-23 10:38:23
【问题描述】:

我一直在调整我在教程和其他帖子中看到的独特电子邮件验证代码。但是,我的代码似乎没有什么能完美运行。

public function register_client($post_obj) 
{
    //client registration
    $record = array
    (
        'first_name'        => $post_obj['c_fname'],
        'last_name'         => $post_obj['c_lname'],
        'email_address'     => $post_obj['c_eadd'],
        'password'          => $post_obj['c_pword'],
        'address'           => $post_obj['c_add'],
        'tagline'           => $post_obj['c_tagline'],
        'profile'           => $post_obj['c_profile'],
        'interests'         => $post_obj['c_interest'],
        'billing_mode'      => $post_obj['c_bmode']
    );
    $this->db->insert('client', $record);
}

在我的控制器中我有这个:

    public function client_signup_submit() 
{
    // completes client registration

    /*$post_email = $this->input->post('c_eadd');
    $this->form_validation->set_rules('c_eadd', 'Email Address', 'required|trim|xss_clean|valid_email|callback_check_duplicate_email[' . $post_email . ']');
    $this->form_validation->set_message('check_duplicate_email', 'This email already exits. Please write a new email.');

    if ($this->form_validation->run() == FALSE) {
    // validation failed then do that
    $this->load->view('client_signup');
     } else */
    //$this->form_validation->set_rules('c_eadd',Email,'trim|xss_clean|required|valid_email|callback_check_email_exists');
    $this->inspire_model->register_client($_POST);
    redirect("in/client?message=Client Account Registration Completed.");
}

我已经评论了几行,因为它们无论如何都不起作用。我检查了我的系统/库/form_validation,它似乎设置正确。

【问题讨论】:

    标签: php forms codeigniter validation email


    【解决方案1】:

    为什么不按照文档所说的去做:is_unique[users.email] 其中users 是表格,email 是您要检查的字段。 http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html

    $this->form_validation->set_rules('c_eadd', 
        'Email Address',
        'required|trim|xss_clean|valid_email|is_unique[users.email]');
    

    【讨论】:

    • 这似乎有效,因为每当我输入相同的电子邮件添加进行测试时,电子邮件添加字段都会以黄色突出显示。但是没有显示任何消息,并且表单仍在提交..
    • 哦,我明白了。我做了: $this->form_validation->set_rules('c_eadd', 'Email Address', 'required|trim|xss_clean|valid_email|is_unique[client.email_address]'); if ($this->form_validation->run() == FALSE) { echo '
    猜你喜欢
    • 2020-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-22
    • 2014-03-02
    • 2015-01-03
    • 2014-06-12
    • 1970-01-01
    相关资源
    最近更新 更多