Retrieve POST data without knowing exact number of fields

Posted by James on Stack Overflow See other posts from Stack Overflow or by James
Published on 2011-02-02T15:15:05Z Indexed on 2011/02/02 15:25 UTC
Read the original article Hit count: 153

Filed under:
|
|

Hi all!

I'm creating an online poll from scratch which will be held in a database. I'm working on getting a system set up so someone can create a new poll.

I will be having the user fill out a simple HTML form with the Questions and Answers (there may be several answers). The user will be able to add multiple questions and multiple answers for each question.

As the total number of questions and answers will be decided by the user, I need to create some clever PHP to cater for this - however many there are.

When dealing with a static number of questions, it's simple. But I'm having trouble thinking of a way to get all the POST data into individual PHP variables so I can process them.

I was thinking of using a foreach loop, anyone got any ideas?

Sorry for the long winded description! If anyone needs anything clarified, I'd be happy to do so. My problem is that I can't get my head around how to deal with the POST values when I don't know exactly which element of the array will contain what. If things were static with a set number of questions and answers, I'd know $_POST[0] was Question1, etc

Thank you! =)

© Stack Overflow or respective owner

Related posts about php

Related posts about arrays