Details
Description
Here is an example: We have form A and form B
A inherited from B, B inherited from Zend_Form. Form B defines some element and adds it to display group. Form A also defines an element and adds it to display group, defined in form B with Zend_Form_DisplayGroup::addElement() method.
In this case element from form A will be rendered in form properly, but will not work as should - populate and getValue(s) doesn't work for it.
If to add element in form A to the form with Zend_Form::addElement() (not just to display group) it will rendered twice - inside groups and outside of it and became to work.
Code example
Form B
class Form_Bform extends App_Form { public function init() { $this->addElement( 'text', 'el1', array( 'label' => 'Title', 'required' => true, ) ); $this->addDisplayGroup(array('el1'), 'group1', array('legend'=>'legend 1')); } }
Form A
class Form_Aform extends Form_Bform { public function init() { parent::init(); $element = new Zend_Form_Element_Text('el2', array( 'label' => 'Customer type', ) ); //Uncomment the following line and element will be added twice //$this->addElement($element); $this->group1->addElement($element); } }
Element MUST be attached to a form or subform; attaching them ONLY to a DisplayGroup means they will never be rendered. In other words, you need to attach the element to the display group after it is already attached to the form.
In your Form A example, you should be adding the element to the form using $this->addElement(), and then adding it by name to the display group: