I’m currently working on a minimal shop(-ish) script that has to deal with a variable number of form input fields (dropdown lists).
Each “article” has a list of standard options like size, color and material. In addition to that each article can have an indefinite number of “extras”. Each of the extras has an individual name.
So for example a page for article A would be created from the database and has the options size, color, material, length and material (plating).
The article page for article B could show the options size, color, material and edition.
Finally the page for article C might only show the four standard/minimal options.
Now I need a way to read and process all options with a central/single script. It should create a simple list of the options name and selected value. So it can be shown like this:
Article B
- size: huge
- color: hot pink
- material: cardboard
- edition: Super Hyper Special Awesome Edition
I know there is a way using an array of fields to “caputure” all the values, but if I understand correctly I would lose the names of the options (because they would all be named the same to create an array)? So instead of “size: huge” I’d only have “huge”?
If anybody could point me in the right direction, it’d help me a lot. (I feel like I should see the correct way to do this but I’m too blind right now… or too stupid)
Simply iterate over $_POST (or $_GET) :
Then you can make differents things if
$nameis known or not