My code
<form action="index.php" method="post">
<input type="text" name="item" placeholder="item"><br>
<input type="text" name="item" placeholder="item"><br>
<input type="text" name="item" placeholder="item"><br>
<input type="submit" name="submit" value="submit">
</form>
What you see here is a simplefied version of the code I have right now. Others things you can't see at the moment are: there is a function to add more rows (jQuery) and to delete rows (also jQuery). So like name='item(countednumber)'), looks to me somehting not to implement. And I also shouldn't know how I can get all the posted values of item1, item2, item3.... etc.
Question
Is there a way of like posting item in sort of array or something? Just how can I get all the values posted of item and get the posted values in a correct order/way?
I hope someone can help me with my "problem", thanks in advance!
-
you can get all the post variables using a while loopN3R4ZZuRR0– N3R4ZZuRR02017年01月09日 22:33:05 +00:00Commented Jan 9, 2017 at 22:33
-
@VermaJr. — Not with PHP with those names.Quentin– Quentin2017年01月09日 22:35:06 +00:00Commented Jan 9, 2017 at 22:35
-
1Possible duplicate of Posting array from formsidyll– sidyll2017年01月09日 22:35:51 +00:00Commented Jan 9, 2017 at 22:35
2 Answers 2
Use []
in the input names:
<input type="text" name="item[]" placeholder="item">
Then $_POST['item']
will be an array of all the inputs.
1 Comment
PHP will create an array of data within $_GET
or $_POST
if the name ends in []
(or [someIndex]
).
So:
<input type="text" name="item[]" placeholder="item"><br>
<input type="text" name="item[]" placeholder="item"><br>
<input type="text" name="item[]" placeholder="item"><br>
and then
$_POST["item"] # will be an array