Issues

ZF-10958: addDisplayGroup creates input fields twice when using long id's (names)

Description

If you create a Zend Form and add an Element with an id (name) like 'form_data_id234'. You can easily add this form to a displaygroup using addDisplayGroup().

But if your elements id is too long it will be added to the display group and remains in the "main" form too. (Outside of the desired display group.) So this element exists twice in a form. First it appears in the display group and also outside of the group but inside the form.

As the fields name is identical, this would raise a logical validation error... (You could never be sure which field value will be used as the correct input field value.)

Here are some example names which are too long and will appear twice in the form: _form_personDetail_communication_COM_4c808f1c19cb1831254439-element _form_personDetail_communication_COM_4c808f1c19cb1831254439-element

I stumbled upon this error afterI updated from 1.10.7 to 1.11.2. In 1.10.7 everythings works as expected.

Comments

The duplicated fields also appear when you are trying to manually set a field name to something like

"_form_persondetail_communication[123]"

ZF removes the brackets but you will have the fields twice inside your form too.

I assume the fields-id is used as a key to access the field anytime later. So this key might be processed (removing brackets, change length, etc.) will be executed but the "original" id remains untouched anywhere in the form elements config data.

I was not able to reproduce this issue. Can you provide a code sample that reproduces this issue?

I think, it is not a problem of length, but a problem with the hyphen in the name:


// Form
$form = new Zend_Form();

$form->setDecorators(array(
    'FormElements',
    'Form',
));

// Elements
$form->addElement('text', 'first-name', array(
    'label'      => 'First name',
    'decorators' => array(
        'ViewHelper',
        'Label',
    ),
));

$form->addElement('text', 'lastname', array(
    'label'      => 'Last name',
    'decorators' => array(
        'ViewHelper',
        'Label',
    ),
));

// Display group
$form->addDisplayGroup(array('first-name', 'lastname'), 'name', array(
    'decorators' => array(
        'FormElements',
        'Fieldset',
    ),
));

echo $form->render(new Zend_View());


    First name
    First name
        Last name
        

Issue ZF-11729 is a duplicate of this and is resolved/fixed. Tests inspected, no need to add additional unit tests for this specific issue.