Welcome Guest, Not a member yet? Register   Sign In
Form validation callback not working!
#1

[eluser]gedev2006[/eluser]
Hi

Can anyone see why the callback function in my form validation (process() function) is not working? The function is just not getting called (validate_username())

It was working...then all of a sudden it doesn't!

Code:
<?php

class Login extends Controller {
    
    private $user = '';
    
    public function Login() {
        
        parent::Controller();
        
        // if already logged in, then redirect to dashboard!
        if ( $this->authentication->confirm() ) redirect ( 'dashboard', 'location');
        
        // load the users model
        $this->load->model ( 'musers' );
        
    }
    
    public function index() {
        
        // load login form
        $content = $this->load->view ( 'content/login/form',null,true);
        
        // load main layout
        $this->load->view ( 'layouts/main', array ( 'content' => $content ) );
    }
    
    /*
     function: process
     scope: public
     desc: processes supplied login information
    */
    public function process() {
        
        // make sure the post field "process_login" is set to 1
        if ( $this->input->post ( 'process_login') == '1' ) {
            
            // get the user and pass
            $username = $this->input->post ( 'username' );
            $password = $this->input->post ( 'password' );
            
            // set validation rules
            $this->form_validation->set_rules ( 'username', 'Username', 'required|callback_validate_username' );
            $this->form_validation->set_rules ( 'password', 'Password', 'required' );
            
            // make sure the form validates
            if ( $this->form_validation->run() ) {
                
                // check password
                if ( $this->user[0]['password'] == $password ) {
                    
                    // all ok - log the user in
                    $this->authenication->set ( array ( 'logged' => '1', 'username' => $username ) );
                    
                } else {
                    
                    $this->index();
                }
                
                
            } else {
                
                // something went wrong!
                // show the login form
                $this->index();
                
            }
            
        } else {
            
            // show login form
            $this->index();
        }
    }
    
        /* function: validate_username
          scope: public
          desc: validates the username exists
        */
        public function validate_username ( $username ) {
            
            if ( $user = $this->musers->single ( $username ) != false ) {
                
                $this->user = $user;
                
                return true;
            
            } else {
                
                $this->form_validation->set_message ( 'validate_username', 'The username you supplied is invalid!');
                
                return false;
            }
        }
}


Messages In This Thread
Form validation callback not working! - by El Forum - 08-10-2010, 06:17 AM
Form validation callback not working! - by El Forum - 08-10-2010, 06:19 AM
Form validation callback not working! - by El Forum - 08-10-2010, 07:40 AM
Form validation callback not working! - by El Forum - 10-14-2010, 09:16 PM
Form validation callback not working! - by El Forum - 10-15-2010, 12:05 AM



Theme © iAndrew 2016 - Forum software by © MyBB