Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does form processing logic belong in a MVC web application?

In a web-based application that uses the Model-View-Controller design pattern, the logic relating to processing form submissions seems to belong somewhere in between the Model layer and the Controller layer. This is especially true in the case of a complex form (i.e. where form processing goes well beyond simple CRUD operations).

What's the best way to conceptualize this? Are forms simply a kind of glue between models and controllers? Or does form logic belong squarely in the M or C camp?

EDIT: I understand the basic flow of information in an MVC application (see chills42's answer for a summary). My question is where the form processing logic belongs - in the controller, in the model, or somewhere else?

like image 769
AdamTheHutt Avatar asked Dec 05 '08 19:12

AdamTheHutt


People also ask

Where does logic for the view belong in MVC?

The Purpose of MVC Framework Input logic belongs in the controller. This separation helps you manage complexity when you build an application because it enables you to focus on one aspect of the implementation at a time.

What is application logic in MVC?

MVC enables the application to be extensible and modular by separating the application into three parts: the business logic part, which implements data retrieval and manipulation. the user interface part, which is what the application users see. the controller part, which routes requests to the proper objects.

What are the three components of MVC?

The Model-View-Controller (MVC) architectural pattern separates an application into three main components: the model, the view, and the controller. The ASP.NET MVC framework provides an alternative to the ASP.NET Web Forms pattern for creating MVC-based Web applications.


1 Answers

I'd say this should probably be seen as 2 separate actions...

  1. submitting the form (V -> C)
  2. processing the submission (C -> M)

Speaking in generics, I tend to think as each action as a message between the sections. The full series of messages would be something like this...

  • Display Form (C -> V)
  • Submitted by the user (V -> C)
  • Process contents (C -> M)
  • Processing finished (M -> C)
  • Display Results (C -> V)
like image 95
chills42 Avatar answered Sep 26 '22 22:09

chills42