Part of the EllisLab Network
   
 
validation failing - not sure why
Posted: 03 July 2009 10:22 AM   [ Ignore ]  
Grad Student
Rank
Total Posts:  88
Joined  06-03-2009

I’m following this:
http://codeigniter.com/wiki/Simplelogin/

I know its failing at the validation, its not even getting to the login part.

I always tries to go to /example4/ which isn’t a page, I just put it there so I can see what its doing.  The password for my users is 3 characters.  Its not a high security thing, just to stop outside users from seeing data we’d prefer they didn’t


What am I doing wrong here?


form code

$data['loginform']['submit'] =     array(    'name'        => 'submit',
                                        
'id'          => 'login',
                                        
'value'       => 'Login to ');  
                                      
          
$data['loginform']['user_input'] = array(    'name'        => 'login_username',
                                        
'id'          => 'user_input',
                                        
'value'       => $this->input->post("login_username"));
                                
          
$data['loginform']['pw_input'] = array(      'name'        => 'login_password',
                                        
'id'          => 'pw_input',
                                        
'value'       => '');

 

function that does the login, loads view

function login()
{
      $this
->load->helper('url');
        
$this->load->library('validation');
        
        
//Check incoming variables
        
$rules['login_username']    = "required|min_length[4]|max_length[32]";
        
$rules['login_password']    = "required|min_length[1]|max_length[32]";        

        
$this->validation->set_rules($rules);

        
$fields['login_username'] = 'Username';
        
$fields['login_password'] = 'Password';
        
        
$this->validation->set_fields($fields);
                
        if (
$this->validation->run() == false) {
            
/*
            //If you are using OBSession you can uncomment these lines
            $flashdata = array('error' => true, 'error_text' => $this->validation->error_string);
            $this->session->set_flashdata($flashdata);
            $this->session->set_flashdata($_POST);
            */
            
redirect('/example4/');            

}else
........

}

}
Profile
 
 
Posted: 03 July 2009 10:58 AM   [ Ignore ]   [ # 1 ]  
Grad Student
Rank
Total Posts:  88
Joined  06-03-2009

On further investigation it looks like its ignoring the rule about allowing 2 character passwords and leaving it at 8 characters, still not sure though.

Profile
 
 
Posted: 03 July 2009 05:35 PM   [ Ignore ]   [ # 2 ]  
Research Assistant
RankRankRank
Total Posts:  362
Joined  04-05-2007

The problem you are facing is that you have it so if the validation fails or isn’t run (the == false) then you are redirecting the user. I would imagine your not actually ever seeing the form unless you have it displayed on a separate page.

You should also use the new form_validation library not the old one.

You should have in the

if ($this->validation->run() == false)
{
// show login form here   
}
else
{
  
// take the user to the success page or redirect them somewhere nice
}
Profile
 
 
Posted: 03 July 2009 07:44 PM   [ Ignore ]   [ # 3 ]  
Grad Student
Rank
Total Posts:  88
Joined  06-03-2009

I think I resolved it, or at least figured it out.  I ended up redirecting a few times on the same page, although I thought it was only happening once.  I’ll post if I continue to have problems, thanks smile

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 721, on January 06, 2010 09:38 AM
Total Registered Members: 115026 Total Logged-in Users: 61
Total Topics: 122461 Total Anonymous Users: 1
Total Replies: 647368 Total Guests: 453
Total Posts: 769829    
Members ( View Memberlist )