In previous articles I’ve looked at creating an accessible form using HTML. At the time I mentioned that there were two things we could not do, at least at that stage: (1) make a form look pretty (solved with CSS for forms) and (2) actually do anything with the form information.
We can now solve the latter problem with PHP. But before we send the user’s submitted data anywhere, we must check that they have filled out our form correctly. This is known as “form validation”. (Not to be confused with HTML validation).
There are three steps to validating a form with PHP:
Check that the entered data is correct. If it is, jump to step 3. Otherwise, go to step 2.
Display the form again, preserving any information entered this far and highlighting where errors occur. Allow the user to correct any mistakes and submit the form again, returning to step 1.