[eluser]TheFuzzy0ne[/eluser]
I would suggest always submitting the data to the same controller, and exporting the functionality of each page to individual private methods.
Here's my idea. Now I haven't done it all for you, there are a lot of blanks, but I think it will work.
Code:
<?php
// You'll need to add a route for this controller
// $route['form/(.+)'] = 'form/index/$1';
class Form extends Controller {
function Form()
{
parent::Controller();
$this->load->library('form_validation');
$this->load->helper('url');
}
function index()
{
if ($this->session->flashdata('form_complete') === TRUE)
{
$this->_success();
}
else {
$page = ($this->uri->segment(2)) ? $this->uri->segment(2) : 1;
if ($page == 1)
{
$this->_page1();
}
else if ($page == 2)
{
$this->_page2();
}
else if ($page == 3)
{
$this->_page3();
}
else
{
$this->_success();
}
}
}
function _page1()
{
// Set any validation rules here
if ($this->input->post('submit') && $this->form_validation->run())
{
// Add data to database.
if ($this->input->post('next'))
{
redirect('form/2');
}
}
// Set any errors for the view here.
$this->load->view('page1');
}
function _page2()
{
// Check that the preceding page has been submited. If it has, then
// It's been validated and so is correct. If it's not, redirect to that
// page. You can set a flash data message here if you want, to be displayed
// by the previous controller method.
// Set any validation rules here
if ($this->input->post('submit') && $this->form_validation->run())
{
// Add data to database.
if ($this->input->post('prev'))
{
redirect('form/1');
}
else
{
redirect('form/3');
}
}
// Set any errors for the view here.
$this->load->view('page2');
}
function _page3()
{
// Check that the preceding page has been submited. If it has, then
// It's been validated and so is correct. If it's not, redirect to that
// page. You can set a flashdata message here if you want, to be displayed
// by the previous controller method.
// Set any validation rules here
if ($this->input->post('submit') && $this->form_validation->run())
{
// Add data to database.
if ($this->input->post('prev'))
{
redirect('form/1');
}
else
{
$this->session->set_flashdata('form_completed', TRUE);
redirect('form');
}
}
// Set any errors for the view here.
$this->load->view('page3');
}
function _success()
{
// Move the data from the temp table to the actualy table.
$this->load->view('success');
}
}