Issues

ZF-3782: Zend Form not allowing multiple array elements with the same name.

Issue Type: Bug Created: 2008-07-28T13:31:59.000+0000 Last Updated: 2008-07-28T13:41:21.000+0000 Status: Resolved Fix version(s): Reporter: Matt Haught (matthaught) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Form

Related issues: Attachments:

Description

I need to add multiple select elements (also a few text ones) with the same name, provide[] and price[], to my form. I initially tried to just add it like any regular select but zend_form removed my brackets from the select name and only showed the last select element. So I added isArray to get my brackets I specified back and multiple as false option to the select elements to get rid of it trying to make my single select into a multi. But still it will only renders the last select from the loop. If I specify a unique name for all of them, it renders as it should but it destroys my ability to easily loop through the data when I process it after it is submitted.

Here is what I am using to make this part of the form:

foreach ($items_providers as $ip) {

$form->addElement('select', 'provide[]', array(

    'value' => $ip['providers_id'], 

    'isArray' => true,

    'multiple' => false,

    'MultiOptions' => $providers_options)

);

$form->addElement('text', 'price[]', array(

    'value' => $ip['price'],

    'isArray' => true)

);

//there are more text elements but I stopped here

}

In the end I need something like this rendered:

<option value="" label=""></option>

<option value="2" label="Test1">Test1</option>

<option value="7" label="Test2">Test2</option>



<option value="" label=""></option>

<option value="2" label="Test1">Test1</option>

<option value="7" label="Test2">Test2</option>



<option value="" label=""></option>

<option value="2" label="Test1">Test1</option>

<option value="7" label="Test2">Test2</option>

etc... All I get is one select and one text box when I should get one of each for each loop. I use this so that when I process the submit I can for loop through the provide array and pull the corresponding values from the price array and process each set.

Tried 1.5.3, 1.6.0RC1, and now trunk.

Thanks,

MH

Comments

Posted by Matthew Weier O'Phinney (matthew) on 2008-07-28T13:40:43.000+0000

This sort of thing is simply not possible with Zend_Form's design; elements need to have unique names for purposes of overloading and element retrieval from the form. Based on your structure, I'm inclined to suggest utilizing subforms to aggregate these elements, and then after processing the form aggregating the individual variables in each.

Regardless, there are no changes we can make to accomodate this at this time.

Have you found an issue?

See the Overview section for more details.

Copyright

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

Contacts