I’m trying to build an html form (with enough markup required that letting zend generate it with decorators just isn’t feasible), and I’m using $this->signupForm->getValue('fieldName') in the input value elements.
The form class creates elements normally and adds to the form, and when I was displaying this form the fields were working properly.
However, with the getValue method, half of my form field values are “0”. I did a type check to ensure they’re not null, but getValue is actually returning a string of “0”.
There are no defaults being set. The only thing that appears to be related, is that all fields that have a default value of “0” are defined in a subclass that extends a parent class. However, moving the fields to the parent class seems to have no impact (cache cleared, etc).
These give you an idea on how the form classes are structured:
class Form_Signup extends Base_Form_Signup {
public function __construct($options = null) {
parent::__construct($options);
$address = $this->createElement('checkbox', 'address');
$address->setLabel('Address')->setRequired(true);
// Add our elements
$this->addElement($address);
}
}
class Base_Form_Signup extends Zend_Form {
public function __construct($options = null) {
parent::__construct($options);
// fields defined here do not show 0
// Add our elements
$this->addElement( // adding our elements );
}
}
I think you are having problems because of the way the constructor works in Zend_Form. I think that calling the default decorators in the constructor of each class is causing some things to be overwritten/canceled.
Try using the
init()method as the class was designed to use:you can still pass an
$optionsarray to the constructor if you really have to but you might be better off just usingsetOptions().