Validation: in presentation tier, middle tier or data tier?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
foobaa
Forum Commoner
Posts: 40
Joined: Tue Feb 13, 2007 10:36 am

Validation: in presentation tier, middle tier or data tier?

Post by foobaa »

Hi,

I'm trying to improve a re-usable Form class I've designed - a little pet project. It's the only piece of code I always end up re-using.

I believe in separation of concerns, and maximum re-use, but like to keep it simple - avoiding frameworks wherever possible.

But I'm having trouble working out where to do certain types of validation. For example, checking for a valid email address. Which tier should this be done at? Presentation, middle or data? Once, twice, or even in all three? Ultimately the error needs to be displayed to the user via the Form object.

Any thoughts very welcome!
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: Validation: in presentation tier, middle tier or data tier?

Post by Darhazer »

There should be data format validation (e.g. e-mail format, numeric for numeric fields, etc.) in the presentation layer and always data validation in the data layer, which can validate field based on another field (business rules), end of course, escaping before sending to database, again in the data layer.
foobaa
Forum Commoner
Posts: 40
Joined: Tue Feb 13, 2007 10:36 am

Re: Validation: in presentation tier, middle tier or data tier?

Post by foobaa »

Thanks - that's interesting - I didn't think the data layer should do any validation of business rules - and I honestly didn't think the presentation layer should be responsible for any error checking at all?
Post Reply