- First of all you need to understand the architecture of web applications, most if not all are 3-tier:
a) Client/Presentation - HTML and Javascript, may contain ActiveX/Flash/Java Applets/Silverlight. I will go out on a limb and add native mobile applications which communicate with a backend server. Basically the role of this layer is to provide an interface for the user of the system to interact with it.
b) Business Logic - PHP/RoR/Java where the data from the client is collected, processed and store and where client requests for data are processed and sent back to the client
c) Backend Data Store - provides persistent storage for the system information
- So where do you do the validation, in all layers. Why?
a) Client side - ensure the user enters correct data, required fields etc
b) Business logic - filter, sanitize and validate client data. Run more complex business rules to ensure that the data is well formed for storage. Some of the validation done at the front end is repeated here, due to the fact that there may be different clients, take for example browsers the Javascript can be disabled. It may also accept data from different sources via APIs for example, so it all needs to be validated.
c) Backend Data Store - constraints ensure that the data is well formed for storage and later retrieval.
So where do you focus your validation efforts, use each layer to perform the validation that suits it best, and leave more complex rules for the layer that can handle it