Jump to content


This topic is now archived and is closed to further replies.


Handling input from a form with lots of input fields

Recommended Posts

I have to deal with input that is typed into many, many text fields of an HTML form by users.
The HTML form currently uses a series of statements like:
<input type="text" name="input1">
<input type="text" name="input2">
<input type="text" name="inputN">

Where N is a large number in the multiple hundreds range.

This results in a series of variables ($input1, $input2, $input3.....etc.) whose string values are the text
inputs by the user.

I would like to put all these values in an array (among other things). How do I do this without wrting hundreds of lines that say
etc. etc.

I would like to have a FOR loop that just goes through all the values and puts them into the array.
However, I can't find a way to increment the names of the *variables*, i.e. $input1, $input2, $input3 etc.

Things like using "input".$n, and incrementing $n, don't work.

Nor have I been able to find a way to change the HTML to use statments like input type="text" name="array[10]" and thus use array elements as variable names to begin with.

Any suggestions?

Share this post

Link to post
Share on other sites

[code]<input type="text" name="input[]">
<input type="text" name="input[]">
<input type="text" name="input[]">[/code]

When the form is submitted, $_POST['input'] is an array of those values, so

[code]foreach ($_POST['input'] as $value) {

           // process form value, in this example echo it

           echo $value . '<br />';


Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.