Validating Form Elements
Menu Validating Form Elements
 

Validating Form Elements

Having spent many hours on the development of Village Hall Booking and Rental forms they need to be documented.

The form elements are formatted to your prefered layout and the form submit button triggers the validation code. The html file is embedded in a PHP file along with the validation code. There are various methods you can use to ensure that the data entered into the INPUT elements is correct. Some data can be made mandatory and the format of the data can be check. i.e. dates and email addresses.

Additional checks can be made to ensure terms and conditions have been read.

Top

Example validation code

Checking an email address:

if (empty($_POST["email"])) {
$emailErr = "Email is required";
} else {
$email = test_input($_POST["email"]);
// check if e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
}
}

The individual checks on each INPUT elements are placed within a check function for the form submission request:

if ($_SERVER["REQUEST_METHOD"] == "POST") {
.....
..... Validation code goes here....
.....
}

Links

Top

References: - a note on these

  • Form Validation UX And Best Practices - https:// userpeek.com/blog/form-validation-ux-and- best-practices/

Site design by Tempusfugit Web Design -