ZF-7835: Label-Decorator produces invalid id with Array-Notation/subform and numeric indices

Issue Type: Sub-task Created: 2009-09-12T09:15:22.000+0000 Last Updated: 2013-02-12T08:22:04.000+0000 Status: Closed Fix version(s): Reporter: Sebastian Krebs (kingcrunch) Assignee: Frank Brückner (frosch) Tags: - Zend_Form

Related issues: - ZF-7663



When using multiple elements in a subform with numeric names (ids) the label decorator will create an id like "14-label", buts thats not valid. Its also not possible to change this behavior, because its hardcoded in Decorator/Label.php:317

<pre class="highlight">$decorator->setOptions(array('tag' => $tag,
  'id'  => $this->getElement()->getName() . '-label'));

In the input-tag of the subform-element the name of the subform itself is prepended. This should be also here.


Posted by Sebastian Krebs (kingcrunch) on 2009-09-12T09:24:32.000+0000

This can be a solution: It prepends the Array name (if exists) before the id of the label.


<pre class="highlight">            $id = $this->getElement()->isArray();
            if (is_null($id)) {
                $id = $this->getElement()->getName();
            } else {
                $id = $id . '-' . $this->getElement()->getName();
            $decorator->setOptions(array('tag' => $tag,
                                         'id'  =>  $id . '-label'));

Posted by Jack Tanner (jacktanner) on 2009-10-30T09:06:43.000+0000

VERIFIED. The current behavior produces invalid XHTML.

The right kind of thing to do is to generate the label $id not based on $element->getName but on getFullyQualifiedName, but the array notation uses brackets which are invalid values for id attributes.

Posted by Sasa Stamenkovic (umpirsky) on 2009-11-20T02:17:37.000+0000

@Jack Tanner Brackets can be replaced with dashes.

Posted by Frank Brückner (frosch) on 2012-07-13T07:36:50.000+0000

Hi Sebastian, can you give a short example? Has the subform a numeric name or the element?


Posted by Sebastian Krebs (kingcrunch) on 2012-07-13T07:44:13.000+0000

Sorry, but was 3 years and 3 minor-versions ago...

But as far as I can see in my own repot: The element has the numeric name


Posted by Frank Brückner (frosch) on 2012-07-13T09:00:59.000+0000

Okay, I'll write an unit test.

Thanks for your very quick answer!

Posted by Frank Brückner (frosch) on 2012-07-13T10:17:04.000+0000

Here is an unit test:

<pre class="highlight">
 * @group ZF-7835
public function testRenderingWithSubForm()
    // Form
    $form = new Zend_Form(
             'view'                         => $this->getView(),
             'decorators'                   => array(
             'disableLoadDefaultDecorators' => true,

    // Element
    $element = new Zend_Form_Element(
             'label'      => 'Foo',
             'decorators' => array(
                     array('tag' => 'div')

    // SubForm
    $subform = new Zend_Form_SubForm(
             'decorators' => array(
    $form->addSubForm($subform, 'bar');

    // Test
    $actual   = trim($form->render());
    $expected = '

              . 'Foo

              . PHP_EOL
              . PHP_EOL
              . '';

    $this->assertEquals($expected, $actual);


<pre class="highlight">
OK (21 tests, 40 assertions)

Process finished with exit code 0

Posted by Frank Brückner (frosch) on 2013-02-12T08:22:04.000+0000

The problem was fixed in a previous version.

Have you found an issue?

See the Overview section for more details.


© 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.