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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:56:39+00:00 2026-05-20T05:56:39+00:00

This will make sense with an example: You’ve got a recipe site, that tracks

  • 0

This will make sense with an example:

You’ve got a recipe site, that tracks 3 datapoints:

  • recipe name (salad, chowder, etc.)
  • ingredients (tomato, potato, pork, etc.)
  • ingredient volume (integers only, to keep our example simple)

On the first page of my Recipe Editor we have a form to list the required ingredients.

Recipe: salad
  REQUIRES
    __ tomato
    __ lettuce
    __ cheese
    __ schweddy balls

On the second page, we get a list of all required ingredients and input boxes to enter the required volumes:

Recipe: salad
Ingredient    Volume
 tomato         2
 lettuce        1
 cheese         1

(contrived, I know, but bear with me)

Now that second form’s list of ingredients and <input ... /> boxes are generated dynamically from the database depending on the recipe chosen for editing.

Each ingredient has a numeric ID, so your volume input would look like:

<input type="text" name="17" value="" /> // how many tomatoes?

Once you SUBMIT, you need to process the $_POST array and upload all the ingredients and volumes — but you (or at least I) don’t know in advance what will be in that $_POST array because each recipe calls for different ingredients == $_POST[???]

The super-kludge I thought of was putting all the ingredient IDs into a comma-separated string, stick that into a hidden input field, and the explode it during processing and use it as $_POST keys to pull out the values. This certainly works, but it makes me feel all dirty inside.

Is there a better approach to getting input values out of $_POST when you don’t know your keys in advance?

  • 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-20T05:56:40+00:00Added an answer on May 20, 2026 at 5:56 am

    The easiest way is to use foreach, since $_POST acts just like any other array:

    foreach($_POST as $key => $value)
    {
        switch($key)
        {
            case 17:
            // ...
        }
    }
    

    You can also check for the presence of specific keys using isset():

    if(isset($_POST['17'])) {
        // ...
    }
    

    And for the record: there’s nothing wrong with comma-separated input fields. The best solution is the one that works. 🙂

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

Sidebar

Related Questions

Consider the following code: $(a).attr(disabled, disabled); In IE and FF, this will make anchors
I'm fairly new to C# but I will try to make this quick! ;)
This will require a little setup. Trust me that this is for a good
Im sure this will be a simple one but have a project that started
This will hopefully be an easy one. I have an F# project (latest F#
Hopefully this will not spark a religious war... We have a web based app
I know this will be a difficult question, so I am not necessarily looking
I think this will be easy but I can't see how to do it!
Not certain if this will get much response due to the newness of Windows
Hopefully, this will be an easy answer for someone with Javascript time behind them...

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.