Chapter 13. Form Validation
In this lesson you will learn some techniques for validating form input in a user-friendly way.
The principles of validating user-submitted input are fairly straightforward: Just check each item in $_POST
in turn and make sure it matches a set of criteria. However, making sure the user is able to correct any mistakes and resubmit the form with a minimum of fuss presents a bit more of a challenge.
Enforcing Required Fields
The most basic type of form validation is to enforce that a particular field must contain a value. In the case of a text input that is submitted with no value entered, the element in $_POST
is still created, but it contains an empty value. Therefore, you cannot use isset
to check whether a value was entered; ...
Get Sams Teach Yourself PHP in 10 Minutes now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.