Welcome Guest, Not a member yet? Register   Sign In
Validation Callback function not working
#1

[eluser]terry101[/eluser]
i currently worked on building verification using the callback function. For some reason the callback function isn't working. Other verification functions work.
"dbcheck" is the function which isn't working on the script below. I dont get any errors either. :-S

Controller
Code:
function register(){
        
            $this->load->library('form_validation');
            
            $this->form_validation->set_rules('username', 'Username', 'required|min_length[5]|max_length[12]|xss_clean|callback_dbcheck');
            $this->form_validation->set_rules('name', 'Name', 'required|min_length[3]|max_length[20]|xss_clean');
            $this->form_validation->set_rules('email', 'E-mail', 'required|min_length[3]|max_length[20]|xss_clean|valid_email');
            $this->form_validation->set_rules('password', 'Password', 'required|min_length[3]|max_length[20]|xss_clean');
            $this->form_validation->set_rules('password_conf', 'Re-type Password', 'required|min_length[3]|max_length[20]|xss_clean|matches[password]');
    
            if ($this->form_validation->run() == FALSE) {
            
                $this->load->view('viewregister');
            }
                else {
                $username = $this->input->post('username');
                $name = $this->input->post ('name');
                $email = $this->input->post ('email');
                $password = $this->input->post ('password');
                $this->Usermodel->register_user($username,$name, $email, $password);
                
                echo " you have been registered $username";
                
            }
        }
        
            function dbcheck ($username) {

            $checkusername = array('username' => $username);
            $verifyusername = $this->db->get_where('tbregister', $checkusername);
            if ($verifyusername->num_rows == 1) {
                
            $this->form_validation->set_message('dbcheck','%s already exists!');
                return FALSE;
            }
            else {
                
                return TRUE;
            }
        }
#2

[eluser]CodeIgniteMe[/eluser]
[quote author="terry101" date="1313127978"]
Code:
function dbcheck ($username) {

            $checkusername = array('username' => $username);
            $verifyusername = $this->db->get_where('tbregister', $checkusername);
            if ($verifyusername->num_rows == 1) {
                
            $this->form_validation->set_message('dbcheck','%s already exists!');
                return FALSE;
            }
            else {
                
                return TRUE;
            }
        }
[/quote]

Sorry, could try changing
Code:
if($verifyusername->num_rows == 1)
[code]
to
[code]
if($verifyusername->num_rows() == 1)




Theme © iAndrew 2016 - Forum software by © MyBB