我想在提交按钮单击上发布此html表.
01 - 我想在php代码(服务器端)02中检索此表的数据 - 我还想在另一页上显示该表.
我正在使用
PHP,JQuery
我有表格标签中有很多行的html表.
<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>
Run Code Online (Sandbox Code Playgroud)
===========
每行有4个输入字段(每行4个单元格).和表中的一百行.因此,如果我通过PHP代码中的名称获取值,那么我必须编写大量代码以获得100(行)*4(输入字段)= 400输入.所以我的问题是"实现这一目标的最佳途径是什么"
小智 17
由于您尝试向后端提交具有相同"name"属性的多行输入/选择,因此您需要在这些输入(表行)中的名称值末尾添加方括号[].
<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>
Run Code Online (Sandbox Code Playgroud)
这告诉浏览器为该name属性创建一个数组.
在php中,将其读作$_POST['color_1'][0]和$_POST['color_2'][0],并根据需要循环.
括号在Phil Bailey的答案中,但没有指出.(添加因为最近的搜索引导我这个)
小智 1
您需要在表中添加输入字段来发布数据。喜欢
<input type="text" name="fieldname" value="" />
Run Code Online (Sandbox Code Playgroud)
如果您不想显示字段,则可以使用以下命令隐藏字段type="hidden"
在表单中添加操作属性。
Action 属性指示您的数据将发布到的 URL。
| 归档时间: |
|
| 查看次数: |
64063 次 |
| 最近记录: |