• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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;
        }
    }

#2
[eluser]CroNiX[/eluser]
Because you are using the is_unique rule before your callback, and that error message is from that rule.

#3
[eluser]DarkManX[/eluser]
Hi,

you probably didnt get it right. Just study the manuels again and try some stuff. You have done some nerd coding i dont understand. Big Grin All you need is:

Code:
$this->load->library('form_validation');
$this->form_validation->set_rules('username','Username','is_unique[register.username]');
$this->form_validation->set_message('is_unique','The %s got to be unique');

if(!$this->form_validation->run()){
  // do something when not valide
}else{
  // do when valide
}

#4
[eluser]shivi[/eluser]
noooo i found my mistake i delete is_unique and i also resolved with my callback function thanks very much

#5
[eluser]DarkManX[/eluser]
Your own callback functions do the same as is_unique. No need for redundancy

#6
[eluser]shivi[/eluser]
yess i know very well my callback function do the same as is_unique . but i prefer use my callback function.
there is no question for redundancy okkk thanks

#7
[eluser]M Arfan[/eluser]
Code:
$this->form_validation->set_message('check_Username','Username already exist please choose onther one');
          
return true;
        }else{
            
            return false;
        }



try this


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.