Issues

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:

Description

Problem: When using subforms and Zend_Layout, legend tags for fieldset is added even when legend is empty, which (at least in Firefox 2.0.0.12) 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">
<?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';
Zend_Layout::startMvc();
$frontController = Zend_Controller_Front::getInstance();
$frontController->setControllerDirectory('./app/controllers');
$frontController->dispatch();

app/controllers/indexController.php

<?php
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');
}
}

app/views/scripts/layout.phtml

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

app/views/scripts/index/index.phtml

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

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

zend/form/decorator/fieldset.php

line 90-93:

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

replace with:

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

Comments

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.

Copyright

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

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

Contacts