Welcome Guest, Not a member yet? Register   Sign In
SOLVED Setting Form Validation Rules in a Config File Works in One App, Not in Another (CI2)
#1

[eluser]kirkaracha[/eluser]
<b>Solved:</b> by adding $config to the constructor of MY_Form_validation.php

--
I have two applications running on the same installation of CodeIgniter 2.0.1. In one application I can <a href="http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html#savingtoconfig">set validation rules in a config file</a> and in the other app I can't.

Both apps have MY_Controller, an Admin_Controller that extends MY_Controller, and a MY_Form_validation library. I've checked all the filenames and locations and everything's in the right place and named correctly.

Setting form validation rules in a config file works in this app (login controller):

Code:
public function index() {
    $this->load->helper('url');
    $redirect_url = '/admin/menu';
    if($this->is_admin == TRUE){
        redirect($redirect_url,'location');
    } else {
        $this->load->library('form_validation');

        // set validation rules
        $this->form_validation->set_rules($this->config);

        if($this->form_validation->run('login') == FALSE){
            $data = array(
                'page_type' => 'form'
            );
            $this->layouts->set_title('Log In');
            $this->layouts->view('login/login_form',$data);
        } else {
            redirect($redirect_url,'location');
        }
    }
} // index

This doesn't work in the other app:


Code:
public function index() {
    $this->load->library('form_validation');

    // set validation rules
    $this->form_validation->set_rules($this->config);

    if($this->form_validation->run('login') == FALSE){
        $data = array(
            'page_type' => 'form'
        );
        $this->layouts->set_title('Log In');
        $this->layouts->view('login/login_form',$data);
    } else {
        redirect('/');
    }
} // index

I can only get form validation to work in the second app if I put the rules in the same controller. Why would it work in one app and not in the other?




Theme © iAndrew 2016 - Forum software by © MyBB