WDS 2 - Form Validation
Form validation is done in mainly 2 ways; PHP and JavaScript when concerning our class. When the submit button is clicked for the form you would want a way to check the data before the data is sent anywhere. You only want correct data in the proper format or else it is useless.
With a form the data is collected through input boxes written in HTML usually. Every form will have a way to submit it, usually with a submit button. The two ways I mentioned above, PHP and JavaScript, can both make sure that your data is correct or corrected before it is stored anywhere. Both of these methods have advantages and disadvantages.
PHP is code read only by the server. PHP is never downloaded by the client machine and is not even visible by the client. The server does all of the processing and reading of PHP code. This offers several benefits; first off webpages load faster not having to download the extra coding for the validation, the server is usually a faster computer meaning it can perform calculations much faster than the client’s computer, and it offers security by not providing the client machine access to the code. A large drawback of PHP is that the entire webpage must be reloaded each time it calculates or reads data.
Without form validation information could be in all sorts of forms and could be completely incorrect. With the proper validation scripts in either or both JavaScript and PHP you can be certain your information is as accurate as possible.
A working example can be found in an application that I made using PHP script generator a long time ago. The example is located at http://www.hansenpropertymanagement.com/view.php?id=1. This form uses JavaScript to validate the inputs and then uses PHP to vaildate the inputs before writing them to a MYSQL database on the webserver.