I ended up using a session array and storing data there so that I can reference it again later. I just added my post data from each form into this array and referenced it later in my else block. Thanks for the help!
I am using CodeIgniter for a school project. I have some experience with PHP but am relatively new to this framework. I am having trouble using two forms on one page.
I have one form that displays a dropdown of artists. After clicking the submit button for this form, it updates the second form (another dropdown) on the same page with the portfolios belonging to the artist selected in the first dropdown.
I am trying to echo the values from each form just for testing purposes right now, I will implement other features later. My issue is that after my second form is submitted, the post value for the first form is changed. If I echo the selected value of the first form before submitting the second form, it shows the value that was selected. If I echo the value of the first form after both forms have been submitted, it shows the first available value from that dropdown.
I need to be able to take the values from both of these forms and then use them later after both forms have been submitted. So I can't have the values changing right when I need to use them, obviously, any help would be appreciated. Thank you much.
Controller
public function formtest(){
//Making a call to the model to get an array of artists from the DB
$data = $this->depot_model->get_artists_list();
$this->form_validation->set_rules('artist', 'Artist');// Commenting this out for now, 'required');
$this->form_validation->set_rules('ports', 'Portfolios', 'required');
if ($this->form_validation->run() == FALSE)
{
//Building the artists dropdown form
$data['data'] = form_open('formtest', 'class="superform"')
. form_label('Artist<br/>', 'artist')
. form_dropdown('artist', $data)
. form_submit('mysubmit', 'Submit')
. form_close();
//Setting up a temp array of the selected artist's portfolios
$ports = $this->depot_model->get_portfolios(url_title($data[$this->input->post('artist')]));
//Culling out the names of the portfolios from my temp array
$newdata = array();
foreach($ports as $port){array_push($newdata, $port['name']);}
//Building the artist's portfolio dropdown
$newdata['data'] = form_open('formtest', 'class="superform"')
. form_label('Portfolios<br/>', 'ports')
. form_dropdown('ports', $newdata)
. form_submit('mysubmit', 'Submit')
. form_close();
//Send the information to my view
$this->load->view('formtest', $data);
$this->load->view('formtest', $newdata);
}
else
{
//This echos out the first available value from my dropdown rather than the one I selected.
echo $data[$this->input->post('artist')];
echo "success";
}
}