Allen S
Allen S

Reputation: 3539

PHP: How to deal with a GROUP of HTML input text fields

I've got a bunch of <input type='text' name='input0' /> fields.

The user can add them dynamically so we'd get something like:

<input type='text' name='input0' />
<input type='text' name='input1' />
<input type='text' name='input2' />

...etc. We don't know how many there will be in total. When the form gets submitted, I want to loop through each of these input fields and assign them to a $_POST variable. These are NOT the only input fields in the form, there are other elements such as radio buttons, checkboxes and other text fields. My problem is I need to somehow identify these particular dynamically-generated text fields, and loop through them. How can I do this, when all I get on the server side are the names of the input fields?

Upvotes: 0

Views: 111

Answers (1)

Prisoner
Prisoner

Reputation: 27618

Use:

<input type='text' name='input[]' />

then you can:

foreach($_POST['input'] as $input){
    echo $input;
}

Upvotes: 6

Related Questions