I have a drop down Element_Select that I’m turning into a custom element Element_SelectCustom so that I can populate it with values directly. This is the custom element
<?php
require_once ('Zend/Form/Element/Select.php');
class Zend_Form_Element_SelectCustom extends Zend_Form_Element_Select
{
public function init() {
$this->addMultiOptions(array(
'NULL' => 'Choose Value',
'1' => 'First',
'2' => 'Second',
'3' => 'Third',
));
return parent::init();
}
The problem is that when I add the new custom element to the form and set it to required, it doesn’t fire an error when I don’t choose a value.
$test = new Zend_Form_Element_SelectCustom('test');
$test->setRequired(true);
$this->addElement($test);
I have no idea what’s wrong with it. Is there maybe another method that I need to re-initiate?
You have to change
'NULL'toNULL. The first is a string with the content “NULL” the latter a empty value. An empty string''should be also fine.