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

Issue Type: Bug Created: 2008-03-18T11:30:36.000+0000 Last Updated: 2008-05-05T11:44:41.000+0000 Status: Resolved Fix version(s): - 1.5.2 (15/May/08)

Reporter: EV (evalder) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Form

Related issues: Attachments:


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

<pre class="highlight">
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');


render('index/index.phtml'); ?>


<pre class="highlight">
<?php echo $this->form; ?>

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


line 90-93:

<pre class="highlight">
            if (method_exists($element, 'getLegend')) {
                $legend = $element->getLegend();

replace with:

<pre class="highlight">
            if (method_exists($element, 'getLegend')) {
                $legend = $element->getLegend();
                if ($legend !== null)


Posted by Wil Sinclair (wil) on 2008-03-25T20:29:10.000+0000

Please categorize/fix as needed.

Posted by Matthew Weier O'Phinney (matthew) on 2008-04-22T11:21:25.000+0000

Scheduling for next mini release.

Posted by Matthew Weier O'Phinney (matthew) on 2008-05-02T12:18:58.000+0000

Resolved in trunk and 1.5 release branch

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.