通过via表单提交HTML表格数据(发布) [英] Submit html table data with via form (post)
问题描述
我想在提交按钮单击时发布此html表.
I want to post this html table on submit button click.
01-我想用php代码(服务器端)检索此表的数据 02-我也想在另一页上显示该表.
01 - I want to retrieve the data of this table in php code (server side) 02 - I also want to display this table on another page.
我正在使用
PHP,JQuery
PHP, JQuery
我的html表格的表单标签中有很多行.
I have html table with many rows in form tag.
<form id="frm_test" class="form-vertical" method="post">
<table id="mytable">
<tr>
<td>
<input type="text" name="color_1" value="" />
</td>
<td>
<input type="text" name="color_2" value="" />
</td>
<td>
<input type="text" name="color_3" value="" />
</td>
<td>
<input type="text" name="color_4" value="" />
</td>
</tr>
......
......
......
......
.....
</table>
<input type="submit" name="submit" value="submit" />
</form>
===========
===========
每行有4个输入字段(每行4个单元格).和表中的一百行.因此,如果我通过php代码中的名称获取值,那么我必须编写大量代码才能获得100(行)* 4(输入字段)= 400个输入.所以我的问题是实现这一目标的最佳方法是什么"
there are 4 input fields in each row (4 cells in each row). and hundred rows in table. So if I get value via name in php code then I have to write lot of code to get 100(rows) * 4 (input fields) = 400 inputs. So my question was "What is the best way to achieve this"
推荐答案
由于您尝试向后端提交具有相同名称"属性的多行输入/选择,因此您需要在其中添加方括号[]这些输入中名称值的末尾(在表行中).
Since you are trying to submit multiple rows of inputs/selects with the same 'name' attribute to a backend, you would need to add square brackets [] to the end of the name value in those inputs (in the table rows).
<form>
<input type="number" name="examplevar" />
<table>
<tr>
<td><input type="text" name="color_1[]" /></td>
<td><input type="text" name="color_2[]" /></td>
</tr>
<tr>
<td><input type="text" name="color_1[]" /></td>
<td><input type="text" name="color_2[]" /></td>
</tr>
<table>
<input type="submit" />
</form>
这告诉您的浏览器为该name属性创建一个数组.
This tells your browser to create an array for that name property.
在php中,将其读为$_POST['color_1'][0]
和$_POST['color_2'][0]
,然后根据需要循环.
In php, read it as $_POST['color_1'][0]
and $_POST['color_2'][0]
, and loop as you'd like.
方括号是Phil Bailey的答案,但未指出. (添加是因为最近的搜索使我想到了这一点)
The brackets are in Phil Bailey's answer, but they are not pointed out. (Added because a recent search led me to this)
这篇关于通过via表单提交HTML表格数据(发布)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!