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

#2
[eluser]gedev2006[/eluser]
hmm...it started to work again!

#3
[eluser]intractve[/eluser]
I didn't see anything stand out except that according to CI convention (not strict) Boolean operators are in uppercase. But I do not think that can be causing any of this.

#4
[eluser]Deep Arora[/eluser]
[quote author="gedev2006" date="1281460770"]hmm...it started to work again![/quote]

Any hints how it started working ? I am facing the same issue..callback function suddenly stopped working..

#5
[eluser]CroNiX[/eluser]
Out of curiousity, why are you checking to see if the username is not false? Do you actually set it to boolean FALSE somewhere? Like if they aren't logged in or something? Maybe checking to see if its empty() would be better.
Code:
if ( $user = $this->musers->single ( $username ) != false )
to
Code:
if( ! empty($this->musers->single ( $username )))


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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