Php gets form request string values

I am trying to submit a form in php that contains several identical fields, e.g. maybe several body_stylesand several makeandmodel

when I serialize the form, I get the following output

SelectbsmContainer0=&body_style=hatchback&body_style=mpv&make=bmw&model=5+series+gran+turismo&valueA=200&valueB=800

how can i parse this on php end?

+3
source share
2 answers

Thanks to a certain PHP function, you will have a lot of problems if you do not rename the fields so that the names end with [], after which they appear in $_POSTarrays.

+1
source

Modify your html so that your fields are an HTML array as follows:

<input name="body_style[]" value="" />
<input name="body_style[]" value="" />

Then you can access them through PHP $_GETsuper global like this:

$first_body_style = $_GET['body_style'][0];
$second_body_style = $_GET['body_style'][1];

or

foreach($_GET['body_styles'] as $value) {
    var_dump($value);
}
+5
source

All Articles