$form = new Zend_Form();
$mockDate = new Zend_Form_Element_Text('mock');
$mockDate->addValidator(???????);
$form->addElements(array($mockDate));
$result = $form->isValid();
if ($result) echo "YES!!!";
else echo "NO!!!";
Assumption that the element is in a date format. How do I determine that the date given is greater than or equal to today?
The question is rather old. In the current version of ZF2 it is not necessary to write new validators. Simply add a filter / validator like this:
And it does the job. There is also an option called 'inclusive' which if set to 'true' (in the 'options' of GreaterThan), will allow 'today' to be a valid date
You can create a simple validator to do this:
And add it to the element:
You probably want to check the date with
Zend_Date
for localization of dates and further benefits.For creating custom validates, take a look at writing validators from Zend´s manual.
that's better because uses standardized Zend_Date methods to check dates, the other awsner user a string comparison that can evaluate to impredictable values...