I have a table form like this:
我有一个这样的表格形式:
<table class="table table-striped table-bordered table-condensed">
<tbody>
<tr><td><input type="text" class="input-small" name="article" /></td>
<td>
<select name="colore">
<option value="nabuk">Nabuk</option>
<option value="nero">Nero</option>
<option value="blu">Blu</option>
<option value="rosso">Rosso</option>
</select>
</td>
<td>
<select name="fondo">
<option value="gomma">Gomma</option>
<option value="cuoio">Cuoio</option>
<option value="legno">Legno</option>
</select>
</td>
<td>
<select name="numero">
<option value="36">36</option>
<option value="37">37</option>
<option value="38">38</option>
<option value="39">39</option>
</select></td>
<td><input type="number" class="input-mini" min="1" max="200" name="qnt" step="1" /></td>
<td></td>
</tr>
</tbody>
</table>
The user can add many rows to this table with a Jquery script. This script is OK and work properly. After that, the table form is submitted through an Ajax post call to a PHP page with the $('form').serialize();
function of Jquery.
用户可以使用Jquery脚本向此表添加许多行。这个脚本没问题且工作正常。之后,表格形式通过Ajax post调用提交到$('form')的PHP页面.serialize(); Jquery的功能。
The problem is: how can I retrieve the values of each field of rows to the server side (PHP), without using hidden supplementary field (for example that submits the number of row in the table) or without use a progressive index for the name of the rows fields?
问题是:如何检索每个行字段的值到服务器端(PHP),而不使用隐藏的补充字段(例如,提交表中的行数)或不使用名称的渐进索引行字段?
I haven't found something that explains the solution... :|
我还没有找到解释解决方案的东西......:
the next step of this script is passing the values of the table to the PHP with JSON object... but it's a secondary problem :)
这个脚本的下一步是将表的值传递给带有JSON对象的PHP ......但这是次要问题:)
1 个解决方案
#1
5
You can use an array. Name your fields with []
at the end of them. For example,
您可以使用数组。使用[]末尾的[]命名字段。例如,
<select name="colore[]">
...
<select name="fondo[]">
...
<select name="numero[]">
PHP will automatically update the indices as
PHP将自动更新索引
$_POST['colore'][0]
$_POST['colore'][1]
$_POST['colore'][2]
etc.
#1
5
You can use an array. Name your fields with []
at the end of them. For example,
您可以使用数组。使用[]末尾的[]命名字段。例如,
<select name="colore[]">
...
<select name="fondo[]">
...
<select name="numero[]">
PHP will automatically update the indices as
PHP将自动更新索引
$_POST['colore'][0]
$_POST['colore'][1]
$_POST['colore'][2]
etc.