ZF-2913: Legend tags for fieldset is added even when legend is empty


Problem: When using subforms and Zend_Layout, legend tags for fieldset is added even when legend is empty, which (at least in Firefox may result in an empty space in the graphical output for the fieldset border where the legend would be.

Various setLegend methods (in Zend_Form, Zend_Form_DisplayGroupand Zend_Form_Decorator_Fieldset) will force string type, so after Zend_Form_Decorator_Fieldset::getLegend() calls $this->setLegend($legend) on line 92 and $legend is NULL, $this->_legend will be an empty string instead of the correct NULL value.

This may also trigger a strange behaviour/bug (ZF-2914) with Zend_Translate if using the gettext adapter - when trying to translate the empty string in method Zend_Form_Decorator_Fieldset::render(), the gettext file header information will be displayed.

Reproduction code: index.php

require_once 'Zend/Loader.php';
require_once 'Zend/Controller/Front.php';
require_once 'Zend/Form.php';
require_once 'Zend/Form/SubForm.php';
require_once 'Zend/Layout.php';
$frontController = Zend_Controller_Front::getInstance();

class IndexController extends Zend_Controller_Action
    function indexAction()
        $this->view->form = new Zend_Form;
        $this->view->form->addSubForm(new Zend_Form_SubForm(array(
            'action' => Zend_Controller_Front::getInstance()->getBaseUrl() . '/form/test',
            'method' => 'post',
            'elements' => array(
                'test' => 'text',
                'submit' => 'submit'
        )), 'name');

<?php echo $this->render('index/index.phtml'); ?>


<?php echo $this->form; ?>

Suggested solution: Don't call setLegend when new value should be NULL.


line 90-93:

            if (method_exists($element, 'getLegend')) {
                $legend = $element->getLegend();

replace with:

            if (method_exists($element, 'getLegend')) {
                $legend = $element->getLegend();
                if ($legend !== null)


Please categorize/fix as needed.

Scheduling for next mini release.

Resolved in trunk and 1.5 release branch