views:

556

answers:

5

Why should I bother to use JavaScript for form validation when I still have to use PHP since the user could have JavaScript support turned off.

Isn't it unnecessary?

Update:

Ok thanks for your answers. it sounds like a good idea to have it on the client side too. where can I download good JavaScript validations?

Do you know where I can download a validation script like that one in yahoo when you register an account?

+3  A: 

... as courtesy to the users pretty much. Makes life easier for the ordinary users that simply commit human things from time to time.

vector
Seconded. Especially on slow connections, Javascript warnings informing about mistakes are a great enhancement in convenience.
Pekka
+18  A: 
David Thomas
+1  A: 

It's a matter of whether you want your form (and website as a whole) to be interactive-cum-user-friendly or not. You can just let the server-side do the validations and throw the error back to the users but that would be less interactive and less user-friendly than warning the users before they submit the form (although you still need to validate the inputs on server-side no matter what). Just my 2 cents :P

Lukman
+1  A: 

You should ALWAYS validate in PHP on the SERVER SIDE and validation in JavaScript is CLIENT SIDE validation for user CONVENIENCE. Thanks to validation on client user may find errors in his form without page relodaing. But user may sent form data without data script validation (for example he may not have JS support in web browser), thus always validate on the server side.

doc
+1  A: 

I recommend you using unified server-side and client-side validation using a framework, since it may avoid confronting the user to data valid on client side but rejected by the server, or the opposite (client side too restrictive). Following list of framework give information about server/client side validation: http://en.wikipedia.org/wiki/Comparison_of_web_application_frameworks

snowflake