Reputation: 19496
This may be very obiouvs and simple, but I haven't used it, how can I get a from PHP a dynamic number of input fileds of the same type?
I have a situation where I'd like do make a dynamic number of inputs to send to the PHP page like this:
With jQuery I can add these inputs to increase or decrease the number of characters:
<!-- value is the character id -->
<tr><td><input type="checkbox" name="character" value="1256"></td></tr>
<tr><td><input type="checkbox" name="character" value="85"></td></tr>
<tr><td><input type="checkbox" name="character" value="901"></td></tr>
<tr><td>etc...</td></tr>
And I have a input submit at the end of the table to send data to my php
page, how can I do to get all these characters? Should I do something directly with AJAX
or can I handle it via $_POST
variables?
Upvotes: 0
Views: 2972
Reputation: 4043
Include empty array accessors in the name of your field:
<input type="checkbox" name="character[]" value="1">
<input type="checkbox" name="character[]" value="2">
Then access the post parameter as an array in php like:
foreach($_POST["character"] as $char) { … }
Upvotes: 11