Welcome Guest, Not a member yet? Register   Sign In
Problems with Validation and $data

I'm being introduced to validation here: http://ellislab.com/codeigniter/user-gui...controller

The problem I am having is when my form returns FALSE and I use $this->load->view('myview.php'); any of the $data
variables that were assigned in the action which originally called myview.php is not passed along and I get Undefined variable errors.

I'm sure this is an easy fix... I am just banging my head against the wall on this one. Any help would be appreciated.

Here is my method:

function reg_insert()
        //Validated Fields
        $this->form_validation->set_rules('name', 'Name', 'required');
        //Check if Validated
        if ($this->form_validation->run() == FALSE) {
            $this->db->insert('reg', $_POST);

I now noticed I can solve the problem by including all the $data arrays I've created in my other method into this reg_insert method.

This works, but it seems silly to have all this data in two places? Is there a way to quickly pass a data array from one method to another?

You can create a function where you retrieve the data and call this function in both methods.

Theme © iAndrew 2016 - Forum software by © MyBB