Welcome Guest, Not a member yet? Register   Sign In
validation failing - not sure why
#1

[eluser]deco10[/eluser]
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
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
Code:
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
........

}

}
#2

[eluser]deco10[/eluser]
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.
#3

[eluser]garymardell[/eluser]
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
Code:
if ($this->validation->run() == false)
{
// show login form here  
}
else
{
  // take the user to the success page or redirect them somewhere nice
}
#4

[eluser]deco10[/eluser]
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




Theme © iAndrew 2016 - Forum software by © MyBB