CodeIgniter Forums
Problems with Validation and $data - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Problems with Validation and $data (/thread-13993.html)



Problems with Validation and $data - El Forum - 12-15-2008

[eluser]EvanCalkins[/eluser]
I'm being introduced to validation here: http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html#thecontroller

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:

Code:
function reg_insert()
    {
            
        //Validated Fields
        $this->load->library('form_validation');
        $this->form_validation->set_rules('name', 'Name', 'required');
        
        //Check if Validated
        if ($this->form_validation->run() == FALSE) {
            $this->load->view('camp_submit');
            //redirect('camp');
        }else{
            $this->db->insert('reg', $_POST);
            redirect('camp/show');    
        }
        
    }



Problems with Validation and $data - El Forum - 12-15-2008

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


Problems with Validation and $data - El Forum - 12-15-2008

[eluser]xwero[/eluser]
You can create a function where you retrieve the data and call this function in both methods.