Tying validation to a form
When a form is first rendered, there is little value in having a form class (such as Application\Form\Factory
, described in the previous recipe) tied to a class that can perform filtering or validation (such as the Application\Filter\*
described in the previous recipe). Once the form data has been submitted, however, interest grows. If the form data fails validation, the values can be filtered, and then re-displayed. Validation error messages can be tied to form elements, and rendered next to form fields.
How to do it...
- First of all, be sure to implement the classes defined in the Implementing a Form Factory, Chaining $_POST Filters, and Chaining $_POST Validators recipes.
- We will now turn our attention to the
Application\Form\Factory ...
Get PHP 7: Real World Application Development 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.