class MyForm extends Zend_Form {
const ELEMENT_DAY = 'day';
const ELEMENT_MONTH = 'month';
const ELEMENT_YEAR = 'year';
public function getDay() { return $this->getValue(self::ELEMENT_DAY); }
public function getMonth() { return $this->getValue(self::ELEMENT_MONTH); }
public function getYear() { return $this->getValue(self::ELEMENT_YEAR); }
public function isValid($data) {
$isValid = true;
$day = $this->getDay(); $month = $this->getMonth(); $year = $this->getYear();
if (!checkdate($day, $month, $year)) {
$isValid = false;
$this->getElement(self::ELEMENT_DAY)->addError('Invalid date specified');
}
return parent::isValid($data) && $isValid;
}
public function init() {
$e = $this->createElement('Select', self::ELEMENT_DAY);
$e->setMultiOptions(range(1, 31));
$this->addElement($e);
$e = $this->createElement('Select', self::ELEMENT_MONTH);
$e->setMultiOptions(array_combine(range(1, 12), range('January', 'December')));
$this->addElement($e);
$e = $this->createElement('Select', self::ELEMENT_YEAR);
$e->setMultiOptions(range(idate('Y') - 100, idate('Y')));
$this->addElement($e);
}
}