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 3877494
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:30:15+00:00 2026-05-19T22:30:15+00:00

Using Drupal 6.20. We can setup some form elements like this:- <input type=select name=somename[]><option>ohai</option></select>

  • 0

Using Drupal 6.20.

We can setup some form elements like this:-

<input type="select" name="somename[]"><option>ohai</option></select>

and then cycle through them in PHP with

foreach ($somename as $name) { ... }

I am trying to do the same in Drupal. I have a list of select-elements that are identical in style. The number of elements may change in the future so the form processing has to be dynamic.

If I use the above approach, each element will overwrite the preceding one, so that ultimately only one element is printed to the screen. I can’t write name="somename[$someid]" as that will not interpret $somename as an array.
Does Drupal support this or am I doing it worng?

Also, Is there any other alternative to achieve the same?

  • 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-19T22:30:15+00:00Added an answer on May 19, 2026 at 10:30 pm

    Here is an example to achieve what you are trying to do.

    
    function test_form( &$form_state )
    {
      $form = array();
      $delta = 0;
      $form["test_field"]["#tree"] = TRUE;
      $form["test_field"][$delta++] = array(
            "#type" => "textfield",
            "#title" => "Title",
        );
      $form["test_field"][$delta++] = array(
            "#type" => "textfield",
            "#title" => "Title",
        );
      $form["test_field"][$delta++] = array(
            "#type" => "textfield",
            "#title" => "Title",
        );
      $form["submit"] = array(
            "#type" => "submit",
            "#value" => "Submit",
        );
      return $form;
    }
    

    In your submit & validate function, you will get an array of values under your field’s name.

    Remember, enabling #tree on your element is the key to this approach. Also Drupal’s form API is one of the best forms framework I have worked with.

    Hope this helps.

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

Sidebar

Related Questions

When you create a new content type in Drupal using the Content Creation Kit,
I'd like to manage a timetable using Drupal 6, there are several pieces of
When using Drupal and UberCart, I can view an invoice by going to: admin/store/orders/10006/invoice,
I'm using drupal and a pgsql database, but after long searches I still can't
I'm using Drupal 6 with the ubercart (and required/recommended modules) installed, and I can't
Is anyone out there using Drupal for large scale, business critical enterprise applications? Does
My drupal site (internal) will not display the TinyMCE editor when using Google Chrome
I have the occasion to produce Drupal web sites using development, staging, and production
I'm creating a form using the Content Construction Kit (CCK) in Drupal5. I've added
Using PyObjC , you can use Python to write Cocoa applications for OS X.

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.