ZF-10803: Form ID overrides Fieldset ID and causes duplicate IDs

Description

The form id still overrides fieldset id but only if the fieldset id is not set.

This code :


$form = new Zend_Form();
$form->setDecorators(
    array(
        'FormElements',
        array('Fieldset'),
        'Form',
    )
);
$form->setAttrib('id', 'form-id');
$this->view->form = $form;

Produces this form:




The fix in ZF-10679 just prevent the fieldset id to be overrides by the form's one if the fieldset id is set. But if the fieldset id is not set the form id still override it.

Comments

Those two patch can fixe the bug, i do prefer the first one but both works


Index: Fieldset.php
===================================================================
--- Fieldset.php    (revision 23482)
+++ Fieldset.php    (working copy)
@@ -131,7 +131,7 @@
         $name    = $element->getFullyQualifiedName();
         $id      = (string)$element->getId();
 
-        if (!array_key_exists('id', $attribs) && '' !== $id) {
+        if ((!array_key_exists('id', $attribs) || $attribs['id'] == $id) && '' !== $id) {
             $attribs['id'] = 'fieldset-' . $id;
         }

Index: Fieldset.php
===================================================================
--- Fieldset.php    (revision 23482)
+++ Fieldset.php    (working copy)
@@ -72,6 +72,7 @@
         $options = parent::getOptions();
         if (null !== ($element = $this->getElement())) {
             $attribs = $element->getAttribs();
+            if (array_key_exists('id', $attribs)) unset($attribs['id']);
             $options = array_merge($attribs, $options);
             $this->setOptions($options);
         }

Huh, fix exists for year and a half, but still not in upstream :-(?

come on guys! it's very easy to fix that

Fix and unit test added.

"rebased" the patches, so it can be applied to latest trunk (r24811)

Thanks to Martin.

Fixed in trunk (1.12.0) r24961