Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are forms used in an MVC framework?

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?

like image 893
sqram Avatar asked Dec 17 '25 16:12

sqram


2 Answers

Of course this depends on the specific framework, but this is rather typical:

  • form data is posted to a controller (like all requests)
  • data validation rules are defined in the model
  • the controller runs the data through the model for validation
  • if successfully validated, the controller does whatever it's supposed to do
  • if data is invalid, the controller pushes error messages for invalid fields to the view
  • the view just displays the error messages
like image 107
deceze Avatar answered Dec 20 '25 08:12

deceze


The form submission can be handle in controller. check this

like image 28
Muhammad Zeeshan Avatar answered Dec 20 '25 06:12

Muhammad Zeeshan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!