Welcome Guest, Not a member yet? Register   Sign In
codigniter check username and email availability problem
#1

[eluser]shivi[/eluser]
hello all . my problem is when i check if username or email already exits . but when i try to register with same username and email it always show me the message . The Username field must contain a unique value. The Email field must contain a unique value. why do not show me the message that i want to show in callback function . where is my mistake thanks very much

here is form set_rules
Code:
public function registration_validation(){
        $this->form_validation->set_rules('username','Username','trim|xss_clean|required|min_length[5]|max_length[35]|is_unique[register.username]|callback_check_Username');
        $this->form_validation->set_rules('password','Password','trim|xss_clean|md5|required|matches[rpassword]|min_length[8]');
        $this->form_validation->set_rules('rpassword','Repeat-Password','trim|xss_clean|md5|required|min_length[8]');
        $this->form_validation->set_rules('email','Email','trim|xss_clean|valid_email|required|is_unique[register.email]|callback_check_Email');
        if($this->form_validation->run()){
            
            
        }else{
            $this->load->view('register');
        }
    }

here is my model code where is check if username and email exits or not
Code:
public function checkUsernameAvailability(){
        $this->db->where('username',$this->input->post('username'));
        $query_username = $this->db->get('register');
        if($query_username->num_rows() == 1){
            return false;
        }else{
            return true;
        }
    }
    
    public function checkEmailAvailability(){
        $this->db->where('email',$this->input->post('email'));
        $query_email = $this->db->get('register');
        if($query_email->num_rows() == 1){
            return false;
        }else{
            return true;
        }
    }

and in my main controller i do all this

Code:
public function check_Username(){
        $this->load->model('login_model');
        if($this->login_model->checkUsernameAvailability()){
            $this->form_validation->set_message('check_Username','Username already exist please choose onther one');
            return false;
        }else{
            
            return true;
        }
    }
    
    public function check_Email(){
        $this->load->model('login_model');
        if($this->login_model->checkEmailAvailability()){
            $this->form_validation->set_message('check_Email','Email already in use please choose onther one');
            return false;
        }else{
            
            return true;
        }
    }


Messages In This Thread
codigniter check username and email availability problem - by El Forum - 08-15-2012, 01:28 PM



Theme © iAndrew 2016 - Forum software by © MyBB