3

i am trying to post a form to php that contains multiple identical fields e.g. there can be multiple body_styles and multiple make and model

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 at php end??

2 Answers 2

5

Change your html so that your fields are an HTML "array" like this:

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

Then you can access them via PHP's $_GET super global like so:

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

Or

foreach($_GET['body_styles'] as $value) {
    var_dump($value);
}
Sign up to request clarification or add additional context in comments.

2 Comments

tnx for the answer with example... but David Dorward answered first so i have to accept his answer... +1
@john Umm... No he didn't. 2011-05-20 11:21:53Z versus 2011-05-20 11:23:19Z
1

Thanks to a certain PHP feature, you are going to have a lot of trouble unless you rename the fields so the names end with [], at which point they will appear in $_POST as arrays.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.