Although at first the idea of using V -> C, C -> M, M -> C looks good, any change to the form requires messing up with the controller+model+view. That should be avoided to keep the application logic simple. Here is a very simple extension to the framework that makes it really easy to handle web forms processing, by delegating the form processing logic to a separate class and keeping the MVC architecture to handle the application logic.
For each form you need to process, create a class derived from a generic "webform" class, or the codeigniter model class. Add methods like validate(), process(), display() to this class.
In the controller, the code becomes like this.
class User_controller
{
function login()
{
$form = new LoginForm(); // this is the class you would create
if ($form->validate())
{
$data = $this->user_model->getUserData( $form->userid );
// form processing complete, use the main "user" model to fetch userdata for display,
// or redirect user to another page, update your session, anything you like
}
else
$form->display();
}
}
The display method in the form class loads its own view, and populates post back data as desired. By using the above, there are few advantages:
You don't need to change your main controller if the form display or processing needs changes.
You don't need to change your user model either
Controller remains clean and handle the main page logic
User Model remains cleans and only interacts with database
The framework can itself be updated so that webforms can be loaded using
$this->load->form("login");
......
However, that is only a suggestion that is useful for the codeigniter team.