开发者

PHP: Get a dynamic number of html input fields

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 开发者_StackOverflow中文版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?


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) { … }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜