It is very essential to have the input to your form validated before taking the form submission data for further processing.When there are many fields in the form, the PHP validation script becomes too complex.In many cases, what may be perfectly fine in one situation won't be correct in another. If you want to verify that someone has entered only two names, such as "Alfred Aho," you can check against: ; but then Donald E. So think carefully about the entire range of valid input before writing your regular expression.
One particularly popular and tricky task is validating an email address, as discussed in Recipe 13.7. You can check against a listing of names, but what if she enters her postal service abbreviation? Using a element, users are forced by the form's design to select a state in the format that always works, which can reduce errors.
Another is how to make sure a user has correctly entered the name of her U. This, however, presents another series of difficulties.
There are a number of ways to solve these types of problems. (Otherwise, she'll probably just pick a place at random, so she can continue using your site.) Next, you can divide the registration process into a two-part sequence.
First, you can provide an "other" option in the list, so that a non-U. For a long list of options, a user begins by picking the letter of the alphabet his choice begins with; then, a new page provides him with a list containing only the choices beginning with that letter. What do you do when you want to make sure the user has correctly entered information, but you don't want to tell her you did so?
Sending data is not enough — we also need to make sure that the data users fill out in forms is in the correct format that we need to process it successfully, and that it won't break our applications.
We also want to help our users to fill out our forms correctly and not get frustrated when trying to use our apps.
You also don't want to allow her to just guess codes, because then she could try out those codes and crack the system. A user enters her code twice; if the two fields match, you accept the data as legal and then (silently) validate the data.
If the fields don't match, you reject the entry and have the user fix it.
Form validation helps us achieve these goals — this article tells you what you need to know.