Hi
I know this is an old thread, but I've had a hunt around in the code as I
needed this functionality, and I think I've found something that unlocks it
all.
For the element to show in the submitted values, you do have to use
Zend_Form::addElement(). However, to show in the display group, you ALSO
have to call Zend_Form_DisplayGroup::addElement().
The obvious issue here is that the element then shows in both contexts and
renders twice on your form. Not great.
To get around this, you need to unset Zend_Form::_order[element_name] - this
seems to remove the element from the render queue. The
Zend_Form::addDisplayGroup function does this currently as part of moving
the elements to the about-to-be-created group.
However, _order is a protected item, so I'm using a custom Form subclass
whch contains the following function which takes an element and drops it
straight into the DG and Form (i.e. one line of code...):
public function addToDisplayGroup($elements, $name) {
$dg = $this->getDisplayGroup($name); // get hold of the display
group
// make it work with either a single element or an array of them
if (!is_array($elements)) {
$aryElements[] = $elements;
} else {
$aryElements = $elements;
}
foreach($aryElements as $element) {
// add the element to the form
$this->addElement($element);
// remove from the render queue
unset($this->_order[$element->getName()]);
// add to the DG
$dg->addElement($element);
}
}
Hope that helps someone... :)
Kiers
--
View this message in context:
http://zend-framework-community.634137.n4.nabble.com/Zend-Form-Adding-elements-to-an-existing-display-group-tp662030p4656433.html
Sent from the Zend Framework mailing list archive at Nabble.com.
--
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]