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.
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
class, and add properties and setters that allow us to attach instances ofApplication\Filter\Filter
andApplication\Filter\Validator
. We also need define$data
, which will be used to retain the filtered and/or validated data:const...