Issues

ZF-9386: Zend_Form_Element::setBelongsTo is always filled with $form->getElementsBelongTo() in Decorator_FormElements

Description

In the Docs http://framework.zend.com/manual/en/…

Zend_Form::setElementsBelongTo($array): Using this method, you can specify the name of an array to which all elements of the form belong. You can determine the name using the getElementsBelongTo() accessor.

Additionally, on the element level, you can specify individual elements may belong to particular arrays using Zend_Form_Element::setBelongsTo() method. To discover what this value is -- whether set explicitly or implicitly via the form -- you may use the getBelongsTo() accessor.

But actually setting belongsTo on the element level in combination with setting elementsBelongTo on the (Sub)Form level discards the element level setting.


$form = new Zend_Form();
$form->setName('form');
$form->setElementsBelongTo('form');

$sub = new Zend_Form_SubForm(
    array(
        'elementsBelongTo' => 'subform[elementsBelongTo]',
        'elements' => array(
            array(
                'type' => 'Text',
                'name' => 'inputText',
                'options' => array(
                'belongsTo' => 'element[belongsTo]'
)))));

$form->addSubForm($sub,'foo');
$form->render();

renders the input like


And when setting belongsTo after adding the SubForm to the Form


$form->addSubForm($sub);
$sub->getElement('inputText')->setBelongsTo('element[belongsTo]');
$form->render();

again


Comments

My question is then, what would be the expected value for getBelongsTo()?

1.) form[subform][elementsBelongTo][element][belongsTo][inputText] 2.) form[element][belongsTo][inputText] 3.) element[belongsTo][inputText]

Number 1 is the only one i can think of at the moment how to implement.

I mean because 2 and 3 makes it rather heavy for Zend_Form to populate, getValues and Validate.

The question was wrong asked, it should be what is the expected rendered name for the Element, if it has one.

This is fixed with ZF-9451