Client-side validation is very useful, and saves a lot of time. However, if there is no server-side validation to make sure that the input is correct, then there is no guarantee that the data you collect will be correct.
In this case, PHP is very useful to us to manage the form. When you think of it, the form would be defined in the following three areas:
In the document's
head
section as part of the JavaScriptIn the
body
section in the HTML formOn the server side when validating and submitting the code
If any one of these was different to the rest, then there would be problems.
The simplest way to solve this is to have a single definition of the form in PHP, from which the HTML and JavaScript should be built.
However, HTML is a layout language, and even the simplest form can be laid out in many different ways. For now, we will combine the PHP and JavaScript. Creating a form builder that builds up forms including their validation rules and their layout is...