PHP form data into array
In this small article I will show you how to send form data in case of multiple selection.
Step 1 - PHP form with multiple selection
PHP form data into array
During PHP form processing it often occurs that the visitor can select multiple answers. It is in case of checkboxes, list- and combboxes. Let's suppose the following HTML form element:
Code:
In this example the visitor can select more color at once. This is the result of the MULTIPLE parameter inside the SELECT tag.
If you check the $_POST superglobal you will find all form variables in it. However if you check it more precisely you will find that the color variable contains only one of your selection. Where are the other selected values? Yes, they are missing in this case.
To solve this problem it would be nice if we would get an array with all of the user selection. Fortunately it is a quite simple task. You just need to edit the name parameter in your HTML form and add a [] after it as follows:
Code:
Using this code you will get an array named color inside the $_POST array and this internal array contains all of the user selected values.
That's all.
Tags: php form array, php form multiple selection, multiple selection form array
| PHP form data into array - Table of contents |
|---|
| Step 1 - PHP form with multiple selection |