Zend Framework provide the validate class to validate the forms elements. Zend have this class in library. This tag is for validation in zend framework.
The Zend_Validate component provides a set of commonly needed validators. It also provides a simple validator chaining mechanism by which multiple validators may be applied to a single datum in a user-defined order.
Zend_Validate
supplies a set of commonly needed validators, but inevitably, developers will wish to write custom validators for their particular needs. The task of writing a custom validator is described in this section.
Zend_Validate_Interface
defines two methods, isValid()
and getMessages()
, that may be implemented by user classes in order to create custom validation objects. An object that implements Zend_Validate_Interface
interface may be added to a validator chain with Zend_Validate::addValidator()
. Such objects may also be used with Zend_Filter_Input
.
As you may already have inferred from the above description of Zend_Validate_Interface
, validation classes provided with Zend Framework return a boolean value for whether or not a value validates successfully. They also provide information about why a value failed validation. The availability of the reasons for validation failures may be valuable to an application for various purposes, such as providing statistics for usability analysis.
Basic validation failure message functionality is implemented in Zend_Validate_Abstract
. To include this functionality when creating a validation class, simply extend Zend_Validate_Abstract
. In the extending class you would implement the isValid()
method logic and define the message variables and message templates that correspond to the types of validation failures that can occur. If a value fails your validation tests, then isValid()
should return FALSE. If the value passes your validation tests, then isValid()
should return TRUE.