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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:54:20+00:00 2026-06-04T22:54:20+00:00

I am creating a form based on a user selection of $node_number … so

  • 0

I am creating a form based on a user selection of $node_number … so the form looks like:

function createForm($node_number) {
            echo "<form id=\"form\" name=\"form\" action=\"molecule_display.php\" method=\"post\">";
           for ($n = 1; $n <= $node_number; $n++) {
                echo "<fieldset class=\"step\">
                            <input id=\"node_title" . $n . "\" name=\"node_title" . $n . "\" />
                            <input id=\"node_comment" . $n . "\" name=\"node_comment" . $n . "\" type=\"textarea\"  />
                     </fieldset>";
                            }
            echo "<input type=\"hidden\" name=\"node_number\" value=\"" . $node_number . "\">
                    <button id=\"submit_node\" type=\"submit\">Submit</button>"
            echo "</form>";
            }

Which will create $node_number of versions of that form element. My question is how to dynamically name the form elements to be able to manage them easier when I am processing them. The way I’m doing it right now, by adding the $n iterator to the name attribute is not ideal I think.

I understand that I can declare the name=”” attribute as an array like name[]=”” … in terms of giving each sub-element of the larger form a unique name.

I’m guessing I want a multi-dimensional array of the individual form segment … just not sure how to best handle those within a form and within the $_POST variable.

Does anyone have any suggestions?

  • 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-04T22:54:22+00:00Added an answer on June 4, 2026 at 10:54 pm

    I think you can do it this way:

    function createForm($node_number) {
        echo '<form id="form" name="form" action="molecule_display.php" method="post">';
        for ($n = 1; $n <= $node_number; $n++) {
            echo '<fieldset class="step">
            <input id="node_title'.$n.'" name="nodes['.$n.'][node_title]" />
            <input id="node_comment'.$n.'" name="nodes['.$n.'][node_comment]" type="textarea"  />
            <button id="submit_node" type="submit">Submit</button></p>
            </fieldset>';
        }
        echo '</form>';
    }
    

    And then get $_POST['nodes'] which will be multidimensional array, which you can iterate with foreach. You will get $_POST['nodes'][1] = array('node_title'=>... , 'node_comment'=>...); and so on.

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

Sidebar

Related Questions

I'm creating a web page based on user input from a form. After the
I've been reading this post Creating a login form in CodeIgniter based on Ion
I'm creating a capture form on the fly based on a set of metadata
I'm creating a form where user can select between 3 types of predefined letters
I am creating a form where a user will register with a struts2 application.
I am creating a form, and giving user three options. They can select only
I am creating buttons dynamically for a user-based app. Now I have to tell
I have been creating user login form using the various groupcodes, the user login
I'm creating a wizard-based series of forms for taking user inputs. One of the
I'm building a website with codeigniter and I'm creating a form for user submission.

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.