tags:

views:

60

answers:

2

What part in the MVC does user input get validated? For example, user registration system, the user inputs data in the View, where does the user's input get cleaned and validated for the correct input, eg. correct email, applying php cleaning functions..would this happen in the controller or the model? and which would decide what errors are returned

thanks

+3  A: 

As per the classic MVC model (graphical apps), user input is a model too. Most PHP framweworks follow the Passive-MVC or MVC-2 model, where it's the domain of the controller or controller helpers. Do what looks most maintainable.

mario
+1 for *Do what looks most maintainable.*
Gordon
another +1, logical :) thanks
dre1080
A: 

In my opinion, it all depends on what kind of validation you want to perform:
1. If you don't want a field to be empty or be in a specific format, I will do that check on the view layer. This is where most regex could be applied.Only once the user input is valid, is then that I will pass control to the controller for further business logic processing
2. If I want to ensure that a user input(, say a username) is unique or not , I will do that validation on the controller side and pass any feeback back to the view. In the latter, the controller might have a dependency on an abstraction of a data access layer or service layer or any other controller helpers.
3. Still have to rationalize on the approach to use.

walters
+1 for this..valid points thanks
dre1080
I am still waiting for the +1. LOL. You are welcomed.
walters