Welcome Guest, Not a member yet? Register   Sign In
Custom form validation not working!

Here's my code:

function register(){
        $data['page'] = 'user/register';
        $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);
        $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;
                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?


Theme © iAndrew 2016 - Forum software by © MyBB