Reputation: 7201
i have been doing simple MVC tutorials for a while and i get the concept. But i am wondering, when a form is displayed in a view, how is the form processed? A code to check for form submission must be present in the view file, which doesn't really fit because view should just be for displaying output.
So when you have a form in a view file of an MVC framework, where should the code to check for form submission be?
Upvotes: 3
Views: 4677
Reputation: 8856
The form submission can be handle in controller. check this
Upvotes: 3
Reputation: 2302
The code to check for and validate the form submission should be in the controller or the model, depending upon the type of data received from the form and what you're doing with it. That's the point of MVC. View files should contain only the barest amount of logic necessary to display the page.
Upvotes: 1
Reputation: 766
I think the most common approach would be the controller, since it is the controller that handles all input data (via $_POST, $_GET etc) and then ultimately decides which methods to call to handle that input, and which view to output.
Upvotes: 1
Reputation: 522195
Of course this depends on the specific framework, but this is rather typical:
Upvotes: 4