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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:45:06+00:00 2026-05-16T05:45:06+00:00

I have a form that asks users to input numbers into multiple form fields.

  • 0

I have a form that asks users to input numbers into multiple form fields. They can select how many form fields they would like. I have labelled the form fields as df1, df2, df3 etc. For each extra form field the user adds it will simply plus 1 to the number after df. My problem it trying to capture (using PHP) these fields and put them in an array. To complicate matters the user might not complete a field, e.g. df2 or df15. I am looking for a way to sort through the post form fields that start df1 but eliminate any fields that have been left blank. Then, insert their values (numbers) into an array. Unfortunately, I am getting confused as to how to screen out the posted form fields that are NULL. I have been trying to loop through the fields and increment the number after df but without success.

Any help would be very much appreciated.

Many thanks,

Adam

  • 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-16T05:45:07+00:00Added an answer on May 16, 2026 at 5:45 am

    Note that you can also give your form fields indexed names:

    <input type="text" name="df[1]" />
    <input type="text" name="df[2]" />
    

    They will then be available in an array, for example (depending on your submit method):

    foreach ($_GET['df'] as $num => $val) {
        …
    }
    

    If the index is left out of the form names, PHP will index them automatically, just as when assigning to an array.

    <input name="df[]" />
    <input name="df[]" />
    

    You can create multidimensional arrays this way:

    <label>Foo</label><input name="df[foo][]" /> <!-- $_REQUEST['df']['foo'][0] -->
    <label>Bar</label><input name="df[bar][]" /> <!-- $_REQUEST['df']['bar'][0] -->
    
    <label>Foo</label><input name="df[foo][]" /> <!-- $_REQUEST['df']['foo'][1] -->
    <label>Bar</label><input name="df[bar][]" /> <!-- $_REQUEST['df']['bar'][1] -->
    

    Note that each [] will cause the generated index to be incremented. This means it isn’t terribly useful for multidimensional arrays, other than for the last index. For example, suppose you wanted each $_REQUEST['df'] to hold an array('foo'=>..., 'bar'=>...). The following wouldn’t work:

    <label>Foo</label><input name="df[][foo]" /> <!-- $_REQUEST['df'][0]['foo'] -->
    <label>Bar</label><input name="df[][bar]" /> <!-- $_REQUEST['df'][1]['bar'] -->
    

    Instead, you’d need:

    <label>Foo</label><input name="df[0][foo]" />
    <label>Bar</label><input name="df[0][bar]" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form that I'm submitting through AJAX. The form includes many fields,
I have a form that asks users to enter a start and end time
In my Rails 3 app, I have a form that asks users to write
I have a form that asks for a email and city. The city select
I have a form that accepts user input and asks them to upload a
I use a registration form that asks users to enter their full name into
I have a website that asks numerous users to fill out a form. There
I currently have form that checks if a user has unsubmitted changes when they
I have a form that sends money value e.g <input type=text name=amount value=N50,000.00 NGN
I have a form that has label values that I would like to pass

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.