ZF-10281: Zend_Form removes 0 (zero) from the elements index

Description

Zend_Form should not remove the value 0 (zero) from the elements index of subforms.

When I try to create a subform with the following structure:

Zend_Form removes the 0 (zero) from the attributes, thus leaving:

This is bad because some developers use the elements index to map objects to save in the database (e.g. Doctrine).

Comments

I couldn't reproduce this behaviour. Could you paste code you are using?

I've tried this example code


$subform = new Zend_Form_SubForm('subform');
$subform->setElementsBelongTo('Foo[Bar][0]');

$element = new Zend_Form_Element_Text(array('name' => 'baz'));
$subform->addElement($element);

and it creates this result


which is what you expect.

Sorry for the delay to response your comment

Follow the code:


//personal info (name, email, dob, etc)
$person = new Zend_Form;
$person->setName('Person');
$person->addElement('text', 'name');
//contact form
$contact = new Zend_Form_SubForm;
for ($i = 0; $i <= 3; $i++) {
    //for each contact, i created a subform and append it to contact form
    $contactItem = new Zend_Form_SubForm;
    $contactItem->addElement('text', 'Bar');
    $contact->addSubForm($contactItem, $i);
} 
//so i added the contact form to the main form
$person->addSubForm($contact, 'Contact');

Hmm.. Unfortunatelly I still can't reproduce this behovior :). The code you've provided is producing following html (I'm using ZF 1.10.7):


So it seems correct.

Here is code I've used to check this: [http://pastie.org/1095403].

Men.... you're right! My working copy of ZF is 1.10.6

I related as a 1.10.7 version.

Im so sorry :(