Issues

ZF-9974: Zend_Form_Element->belongsTo not usable with same named multiple elements

Description

Lets say i want to create two arrays inside one form, using belongsTo: if i want to use they same keys for both arrays, i have to name those elements the same. Unfort., even with different ids, there maynot be more than one element what results in the second element (in this case: remove[$i]) overwriting the first (in this case status[$i]).

class My_Form_Random extends Zend_Form {

public function init()
{
    $data = array(1 => 'test1', 2 => 'test2');
    foreach ($data as $field => $val)
    {
        $this->addStatusElement($field, $field, $val);
        $this->addRemoveElement($field);
    }


    $this->addElement('submit', 'submit');

}

protected function addStatusElement($id, $label, $value)
{
    $element = new Zend_Form_Element_Select('add_'.$id);


    $element->addMultiOption(1);
    $element->addMultiOption(2);

    $element->setBelongsTo('status')
            ->setName($id)
            ->setLabel($label)
            ->setValue($value);
    $this->addElement($element);
}

protected function addRemoveElement($id)
{
    $element = new Zend_Form_Element_Checkbox('remove_'.$id);

    $element->setBelongsTo('remove')
            //->setName($id)
            ->setValue(0)
            ->setLabel('Remove');
    $this->addElement($element);
}

Comments

Postponing for Zend Framework 2.0 development.