• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Custom form validation not working!

#1
[eluser]aryan_[/eluser]
Here's my code:


Code:
function register(){
        $data['page'] = 'user/register';
        $this->load->library('session');
        $this->load->library('form_validation');
        $this->form_validation->set_rules('username', 'Username', 'required|xss|trim|callback_username_check');
        if($this->form_validation->run() == TRUE){

            $val['username']    = $this->input->post('username');
            $val['password']    = $this->input->post('password');
            $val['firstname']   = $this->input->post('firstname');
            $val['lastname']    = $this->input->post('lastname');
            
            
            if($this->db->insert('users', $val)){
                $this->session->set_flashdata('isregistered', TRUE);
                redirect(current_url());
            }
            
        }
        
        $this->load->view('tpl', $data);
    }
}

function username_check($un){
        $sql = "SELECT id FROM users WHERE username='{$un}' LIMIT 1";
        $query = $this->db->query($sql);
        if($query->num_rows() > 0){
               $this->form_validation->set_message('check_username', '%s already exists. Please enter another.');
                return FALSE;
        }
        else{
                return TRUE;
        }
    }

Custom validation username_check is not working.

I think my eyes are not sharp enough to find out the issue.

Can you help, please?

Thanks


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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