Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Validation
#1

[eluser]Unknown[/eluser]
Hello guys,

I can't seem to get the validation to work correctly. I'm not getting any errors to check against. It doesn't display the error if the form doesn't have any data when posted. I'd rather use this validation library rather than the form_validation() library.

Thanks for any help you can give me.

Code:
class Login extends Controller {

    // Validate user then set the session using session helper.
    function index() {
                
        $this->load->library('validation');
        $rules['email'] =  "trim|required|valid_email";
        $rules['password'] = "trim|required|min_length[6]";
        $this->validation->set_rules($rules);
        
        // Check if all feilds have been validated or return to is_not_logged_in() function.
            if ( $this->validation->run() == FALSE ) {
                $this->is_not_logged_in();                    
            } else {
                // run query to see if email and password exists in db before creating session.
                $this->load->model('membership_model');
                $query = $this->membership_model->validate();
                
                if($query) {
                    $data = array(
                        'email' => $this->input->post('email'),
                        'is_logged_in' => true
                        );
                    $this->session->set_userdata($data);
                    redirect('app/');    
                } else {
                    // No user was found so reload view;
                    $this->is_not_logged_in();                    
            }
        }
    }
    
    function is_not_logged_in() {
        $data['main_content'] = 'site/login_view';
        $this->load->view('site_template/template', $data);
        
    }
    
    
}

My login_view has the following to display the error:

Code:
&lt;?=validation_errors('<p class="error_msg">') ?&gt;




Theme © iAndrew 2016 - Forum software by © MyBB