Welcome Guest, Not a member yet? Register   Sign In
Form validation false interrupting the pagination - help !
#1

[eluser]chaminda[/eluser]
Guys,

When my form validation fail at login, pagination doesn't work. but when the login successful it works like a charm. i tried to initialize the pagination before the form validation rules and pass pagination along with the view. but no luck. can anyone help me to understand why is this happening?

Code:
function login()
    {
        
        $data['records'] = $this->main_model->get_records();
        $total = $this->main_model->count_records();
        $this->load->library('pagination');

        $config['base_url'] = base_url() . 'main/index';
        $config['total_rows'] = $total;
        $config['per_page'] = '20';

        $this->pagination->initialize($config);

        $data['pagination'] =  $this->pagination->create_links();
        
        $this->form_validation->set_rules('username','Username','required|trim|max_length[50]|xss_clean');
        $this->form_validation->set_rules('password','Password','required|trim|max_length[200]|xss_clean');
        
        
        
        if($this->form_validation->run() == FALSE)
        {
            $this->load->view('index',$data);
        }
        
        else
                //Process the form and log in the user
        {
            $username = $this->input->post('username');
            $password = $this->input->post('password');
            $userid = $this->main_model->get_user($username, $password);
            
            if(!$userid)
            {
                //User not avilable
            $this->session->set_flashdata('login_failed',TRUE);
            redirect('main/login');
            $this->load->view('index');
                
            }
            
            else
            {
                //User avilable. log him in
                $login_data = array('logged_in' => TRUE, 'username' => $username);
                $this->session->set_userdata($login_data);
                redirect('main/index');
            }
        }
        
    }


Messages In This Thread
Form validation false interrupting the pagination - help ! - by El Forum - 05-23-2011, 08:11 PM



Theme © iAndrew 2016 - Forum software by © MyBB