Basically I want my multi-part form’s controller to have a single function that gives the post data to the other functions like preview and edit.
The function is below:
function get_post_data()
{
$post_data_array = array();
// declaration of all form field names
$variable_array = array('form_field_1', 'form_field_2', ... 'form_field_n');
for ($i = 0; $i < count($variable_array); $i++) {
$variable_value = $this->input->post($variable_array[$i]);
// turn them into an easy-to-use array
$post_data_array[$variable_array[$i]] = $variable_value;
}
return $post_data_array;
}
So that functions will access it as:
function show_preview_form()
{
$this->load->view('preview_form_view', $this->get_post_data() );
}
function send_to_database()
{
$data_array = $this->get_post_data();
$this->Model->insert_to_database($data_array['form_field_1'], ...);
}
Currently it does not work. Firebug returns a 500 Internal Status Error status. Do you guys know how to solve this?
I really don’t want to repeat the long get_post_data in every function that needs it.
you need to assign a empty array to
$post_data_arraybefore can add values to it.in the beginning of
get_post_datafunction add$post_data_array = array();update:
its probably also a good idea to change
get_post_datato_get_post_datathat way its not accessible directly from the url.http://ellislab.com/codeigniter/user-guide/general/controllers.html#private