I have a Controller named Author
. Inside the controller, I have defined a submit function that takes care of the 3-step form process. Right now I have only created the first form.
class Author extends CI_Controller {
public function index() {
}
public function submit() {
$this->load->view('author/submit_step1');
}
}
The form1 that is loaded in the view points to the URL (action)
http://localhost/zabjournal/Author/submit/2
My objective is to save the values of the first form to a database, and then load the 2nd form.
Given the action of the form, How should I design the controller so that I can access a model and save the details of the first form, and then load the view for the 2nd form.
You could do something like this:
public function submit (){
if ($this->input->post('submit-1')) //Use unique names for each submit button value on the forms
{
//validate and save form data to database
$this->load->view('author/submit_step2');
}
elseif ($this->input->post('submit-2'))
{
//validate and save form data to database
$this->load->view ('author/submit_step3');
}
elseif ($this->input->post('submit-3'))
{
//validate and save form data to database
$this->load->view('author/success');
}
else
{
$this->load->view('author/submit_step1');
}
}
you can also use the redirect function to the controller that loads the second form.
For example
//the function that loads the first form<br><br>
public function load_firstForm() {
$this->load->view('author/form1');
}
//in your form1 use form_open('author/submit_step1') to access the second function
public function submit_step1() {
//load your model here and a method to save these items
//redirect to the same controller but the second method that loads the second form
redirect('author/submit_step2');
}
//function that loads form2
public function submit_step2() {
$this->load->view('author/form2');//loads the second form
}
etc. Hope this helps.