rgrne Posted May 13, 2006 Share Posted May 13, 2006 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$array[1]=$input1;$array[2]=$input2;$array[3]=$input3;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? Quote Link to comment Share on other sites More sharing options...
Barand Posted May 13, 2006 Share Posted May 13, 2006 Use[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 />';}[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.