Adding custom callback to Codeigniter Form Validation

前端 未结 3 1756
小鲜肉
小鲜肉 2020-12-09 06:47

I want to limit my registration to emails with @mywork.com I made the following in My_Form_validation.

public function email_check($email)
    {
        $fin         


        
3条回答
  •  萌比男神i
    2020-12-09 07:13

    Are you need validation something like this in a Codeigniter callback function?

    $this->form_validation->set_rules('email', 'email', 'trim|required|max_length[254]|valid_email|xss_clean|callback_spare_email[' . $this->input->post('email') . ']');
    
    if ($this->form_validation->run() == FALSE)
    {
        // failed
        echo 'FAIL';
    }
    else
    { 
        // success
        echo 'GOOD';
    }
    
    function spare_email($str)
    {
    
        // if first_item and second_item are equal
        if(stristr($str, '@mywork.com') !== FALSE)
        {
        // success
        return $str;
        }
        else
        {
        // set error message
        $this->form_validation->set_message('spare_email', 'No match');
    
        // return fail
        return FALSE;
        }
    }  
    

提交回复
热议问题