I am developing a simple php application with MVC architecture. My model is a user and view is simply a form render. Before submitting data by form to db I want to validate fields form and print if there are errors. Where can I put my validation function, in view or in model?
Asked
Active
Viewed 732 times
0
-
Models are used for database interaction, so the model. – Bankzilla May 24 '15 at 22:22
-
Have you looked at any of the dupes? https://stackoverflow.com/questions/6499499/where-to-validate-and-process-form-submission-in-mvc-website?rq=1 https://stackoverflow.com/questions/5305854/best-place-for-validation-in-model-view-controller-model?rq=1 https://stackoverflow.com/questions/1831442/where-is-the-best-place-to-verify-form-data?rq=1 – PeeHaa May 24 '15 at 22:22
2 Answers
0
In MVC applications, you interact with the database in models. Therefore, if you need to validate your form input with the database, you should do this in a model.

TrickyInt
- 157
- 1
- 8
0
You can validate your form fields in your model
. Alternatively, you might want to use front-end validation with Javascript or JQuery. In this case, you should put your js code to view
.

Mert Metin
- 411
- 1
- 8
- 21