PDA

View Full Version : [Form Validation] What is good practice


Andrewisback
06-16-2008, 10:14 AM
I am starting a website up and have a simple registration form. I need to validate the input and after doing some research the it is better to most of the validating before posting it to the php document.
What i want to know what is the best code to use for this i know that java is a code you can do it with but i thought it was a code that doesn't work on all the browsers.
So is there other codes to use or is java the best one and if so any chance of an example of a validation?

Thanks in advance

Horus_Kol
06-16-2008, 06:54 PM
First:
Java is a code that is compiled and downloaded to the user as an applet - either embedded in a webpage or as a seperate executable.
JavaScript is a popular client side script that most browsers use, and is useful in creating dynamic web pages and things like Ajax.

Just so you know - they are not the same, and don't get them confused.


Now - form validation... you should never rely on client side validation - this can be bypassed or spoofed very easily, and if you do not validate your inputs on the server side you will have a major security hole in your site.

So, no matter what you do, always validate input on the server after a HTTP POST/GET/other request.

Client side validation is intended for to make the user experience smoother - it saves the user from having to POST a form and then wait for the server to respond after validation to see if there is anything wrong.
Since JavaScript is used by almost everyone, there is nothing wrong with using this as your client side validator.
However, as mentioned already, since JavaScript is not used by ALL browsers (such as text or text-to-speech), and can be switched off in others, then you will have to validate on the server, too.