Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8584069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:41:02+00:00 2026-06-11T21:41:02+00:00

I need to obtain something like this in zend <input type=text name=phone[1] value= />

  • 0

I need to obtain something like this in zend

<input type="text" name="phone[1]" value="" />
<input type="text" name="address[1]" value="" />
<input type="text" name="banana[1]" value="whatever" />

Notice they have the same id inside the brackets! (i don’t need name="phone[]" , or name="phone[phone1]")

I’ve tried and
https://stackoverflow.com/a/3673034/579646 and
https://stackoverflow.com/a/406268/579646 and https://stackoverflow.com/a/7061713/579646

The problem is in ZendFramework i end up having to name 3 elements with the same name “1” and the last overwrites the previous. Even if i create 3 subforms i get the same effect.

Different examples show how to obtain an array with different indexes or no index([]), but i need different array to have the same index.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T21:41:03+00:00Added an answer on June 11, 2026 at 9:41 pm

    Zend_Form has a feature for this named setElementsBelongTo. See
    http://framework.zend.com/manual/1.12/en/zend.form.advanced.html

    The way of use this is setting to the Zend_Form object the prefix with setElementsBelongTo, if you want iterate over each field then you can use subforms to encapsulate each group of fields

    You can call to setElementsBelongTo in your controller or in the init() method of your form class:

    $mainForm = new Zend_Form();
    
    $phoneForm = new Zend_Form_Subform();
    $element = $phoneForm->createElement('text', '1'); // 1 is the element inside of the brackets
    $phoneForm->addElement($element);
    $phoneForm->setElementsBelongTo('phone'); // phone is the part leading the brackets
    $mainForm->addSubform($phoneForm, 'phone_form');
    
    $phoneForm = new Zend_Form_Subform();
    $element = $phoneForm->createElement('text', '2'); // 1 is the element inside of the brackets
    $phoneForm->addElement($element);
    $phoneForm->setElementsBelongTo('phone'); // phone is the part leading the brackets
    $mainForm->addSubform($phoneForm, 'phone_form2');
    
    $addressForm = new Zend_Form_Subform();
    $element = $addressForm->createElement('text', '1');
    $addressForm->addElement($element);
    $addressForm->setElementsBelongTo('address');
    $mainForm->addSubform($addressForm, 'address_form');
    
    echo $mainForm;
    
    var_dump($mainForm->getValues());
    

    gives

     array(2) { 
    ["phone"]=> array(2) { [1]=> NULL [2]=> NULL } 
    ["address"]=> array(1) { [1]=> NULL } } 
    

    To get your expected result you will need remove some decorators (Form, dt, etc):

    <input type="text" name="phone[1]" value="" />
    <input type="text" name="address[2]" value="" />
    

    Then when you retrieve the values with $form->getValues() the result is:

    Array(
       'phone' = Array(
           '1' => <value>,
       ),
       'address' = Array(
           '1' => <value>,
       )
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some input text field in a form that have name with this
How to concatenate two variables to obtain something like this? $var = sss; $i
I need to obtain a Date object from this String:This is a example) M-27\nJUN-2012
Need to apply a filter to a file like this: TUPAC_0006:1:1:2554:2356#0/1 0 * 0
what I'd like to do (for logging purposes) is something like this: This code
I have something like this: (pseudocode) public class Author { int id; public List<Thread>
I've done a query like this : SELECT Code, kind, SUM(valP) AS value FROM
Is it possible to export output from apachetop to file? Something like this: apachetop
In my web/MySQL application I have something like this to get distance between two
I need to obtain the number of parameters a given block takes. For example:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.