Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you avoid duplication of validation on the server and client-side?

How do you avoid duplication of validation on the server and client-side? Is there a web programming platform that generates one from the other, so I don't have to keep the two in sync?

like image 694
josh Avatar asked Apr 22 '09 19:04

josh


People also ask

Can server-side validation and client-side validation be used together?

While client-side validation is faster and favors user experience, it should not be used in isolation because client-side validation relies on the browser (which can be tricked). Client-side validation should always be used along with server-side validation as the latter is more reliable.

Why do we do validation on both the client and the server sides?

Your apps should always perform security checks on any form-submitted data on the server-side as well as the client-side, because client-side validation is too easy to bypass, so malicious users can still easily send bad data through to your server.

What is one way in which server-side validation is done?

In the Server Side Validation, the input submitted by the user is being sent to the server and validated using one of server side scripting languages such as ASP.Net, PHP etc. After the validation process on the Server Side, the feedback is sent back to the client by a new dynamically generated web page.

What are the advantages of validating data on the client-side before it is sent to the server?

The advantages to using client-side validation are two-fold users receive feedback quicker (no need to go off to the server, process the information, then download another HTML page), and also it saves load on the server - more work is done on the client side.


1 Answers

There are frameworks that can generate the client-side validation from serverside validation configuration.

Now I don't know what language or frameworks you are using, but maybe this article can be of help: http://www.emadibrahim.com/2008/09/08/client-server-side-validation-in-aspnet-mvc/

He's using Castle Validator Component together with JQuery and adds some glue to generate the clientside validation based on the serverside validation attributes. It's for asp.net mvc.

/Asger

like image 82
asgerhallas Avatar answered Oct 05 '22 02:10

asgerhallas