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

  • Home
  • SEARCH
  • 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 719279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:37:25+00:00 2026-05-14T05:37:25+00:00

I have form, where some fields are looks like rows, so I can add/delete

  • 0

I have form, where some fields are looks like rows, so I can add/delete them using JS.
For example:

Field with ID=1 (existing row)

<input id="id[1]" type="text" name="id[1]" value="1" />
<input id="name[1]" type="text" name="name[1]" value="100" />

Field with ID=2 (existing row)

<input id="name[2]" type="text" name="name[2]" value="200" />
<input id="name[2]" type="text" name="name[2]" value="200" />

new row created by default (to allow add one more row to existing rows)

<input id="id[n0]" type="text" name="id[n0]" value="" />
<input id="name[n0]" type="text" name="name[n0]" value="" />

new row created by JS

<input id="id[n1]" type="text" name="id[n1]" value="" />
<input id="name[n1]" type="text" name="name[n1]" value="" />

So than we will proceed form, we will know what rows to update and what to add (if index starts with “n” – new, if index is number – existent element).

I tried subforms… but do I have to create subform for each field? If I use following code:

$subForm = new Zend_Form_SubForm();
$subForm->addElement('Text', 'n0');
$this->addSubForm($subForm, 'pid');       
$subForm = new Zend_Form_SubForm();
$subForm->addElement('Text', 'n0');
$this->addSubForm($subForm, 'name');

What is the best way for this?

1) Use subforms?

2) Extend Zend/Form/Decorator/ViewHelper.php to use names like name[nX]?

3) Other solutions?

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-05-14T05:37:25+00:00Added an answer on May 14, 2026 at 5:37 am

    The alternative is to create a single sub form with all the fields in place and then add an array of these sub forms to your main form. This is the code I use for that:

            foreach ($value as $id => $row) {
    
                    $subForm = clone $origSubForm;
    
                    $name = 'multi[' . $id . ']';
                    $subForm->setElementsBelongTo($name);
                    $subForm->setName($name);
                    $subForm->populate($row);
    
                    $subForms[$id] = $subForm;
            }
    

    Put these forms in an array element (in this example named multi). Instead of arrays containing the individual $id[] values you get one array containing [0 => ['id' => .., ], 'n0' => ['id' => ...]]

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Ext.form.FieldSet with some fields in it. It looks like: var register_options =
I have a simple form with some plain html input like bellow using ASP.NET
Say you have a web form with some fields that you want to validate
I have a form with multiple fields that I'm validating (some with methods added
On a website if I have a form where the user can input some
I have a form that's checked by jquery validate. The field that's causing some
I have some code that looks like the following coming back from an XHR
Hi I have a form class which looks like below:- class UserCreateForm(wtf.Form): name=wtf.TextField('Name',validators=[validators.Required(),username_check]) email=wtf.TextField('Email')
I have a form with some radio buttons that are disabled by default. When
I have subclassed Form to include some extra functionality, which boils down to a

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.