ZF-10731: addDisplayGroup() should automatically call addElement()


When always using fieldsets with labels, it's very annoying to always use this procedure:

$lenDateFrom = new Zend_Form_Element_Text('lenDateFrom'); $lenDateFrom->setValue($dateFrom); $lenDateFrom->setRequired(); $this->addElement($lenDateFrom);

...more Elements....

$this->addDisplayGroup(array('lenDateFrom', '....', '...', ..), 'name', array('legend' => 'mainData') );

Because that is to much work, I created an wrapper, which would maybe be fine in Zend_Form to:

How does this wrapper works? See example in attached file.

What does the wrapper do? call $this->addElement() call/create addDisplayGroup

How is the call now? $lenDateFrom = new Zend_Form_Element_Text('lenDateFrom'); $lenDateFrom->setValue($dateFrom); $lenDateFrom->setRequired(); $this->addFieldset($lenDateFrom, 'mainData');

At the end of the Form renderFieldsets() is called.

It would need some modifications to be more abstract, but maybe the code snippet is usefull.



@Martin Keckeis Please use code tags! Thanks.

Here's is my suggestion:

public function addDisplayGroup(array $elements, $name, $options = null)
    $group = array();
    foreach ($elements as $element) {
        $elementName = null;
        if (is_string($element)) {
            $elementName = $element;
        if ($element instanceof Zend_Form_Element) {
            $elementName = $element->getName();
            if (!isset($this->_elements[$elementName])) {
        if (isset($this->_elements[$elementName])) {
            $add = $this->getElement($elementName);
            if (null !== $add) {
                $group[] = $add;

This issue is related to ZF-10491.

The attached patch automatically adds the {{Zend_Form_Element}}'s in $element to the form. Therefore calling {{Zend_Form::addElement}} won't be mandatory anymore.

Also, unit tests are included, as well as my fix to ZF-10734 (which isn't committed at this moment)

Fixed r23603 in trunk merged to release branch 1.11 r23604 - thanks.