Many sites feature web forms to collect information from users. Unfortunately, these forms often provide a poor experience for the user, with predictable results. This article will show you how to make filling out web forms more fun (or at least less painful) for your users with the help of PHP and some AJAX magic.
AJAX (asynchronous JavaScript and XML) is becoming more popular on the Internet, particularly when used with PHP. Sadly, lots of good PHP books do not include AJAX as a method to help validate user inputs. Therefore, if beginners are relying on good PHP books, they are entirely new to AJAX validation.
A screen shot below differentiates an AJAX and non-AJAX validation process.
Based on the above screen shot, a non-AJAX web form will reload the page to another URL and show the results of the data validation. The user is then required to click the link or press the back button to go back to the form page URL again. At the form page URL, the user will again type all the entries, because they will be lost when reloading the page.
This process is still common on some websites today. It gives a poor user experience because it takes a lot of time just to complete and validate the form.
With AJAX form validation, after clicking the submit button, the validation results (which provide feedback on the data entry mistakes) are still shown in the form URL WITHOUT reloading the page. This is a convenient method that allows the users to easily retype and correct wrong entries.