【发布时间】:2015-08-04 03:48:34
【问题描述】:
我有一个巨大的表格,里面有一张桌子。当用户按下某个按钮并尝试在 PHP 中捕获所有这些值时,我使用 jQuery 添加该表的行
但除了表格的第一行,我无法得到其他值!
知道了
未定义索引:类别#2
当我试图通过$_POST['categorie#2']得到它时
HTML 看起来像这样:
<form>
...[some working inputs]
<table id="matos" class="table table-responsive synthese">
<thead>
<tr>
<th>Matériel</th>
<th>Fournisseur</th>
<th>Numéro de série</th>
<th>Catégorie</th>
<th>Description</th>
<th>Date d'achat</th>
<th>Etat</th>
</tr>
</thead>
<tbody>
<tr class="" id="ligne#1">
<td><input type="text" name="materiel#1" id="materiel#1" class="form-control" value=""></td>
<td>
<select name="fournisseur#1" id="fournisseur#1" class="form-control" value="">
<?php
$list = listing_fournisseurs();
foreach ($list as $key => $value)
{
echo '<option value='.$key.'>'.$value.'</option>';
}
?>
</select>
</td>
<td><input type="text" name="num_serie#1" id="num_serie#1" class="form-control" value=""></td>
<td>
<select name="categorie#1" id="categorie#1" class="form-control" value="">
<?php
$list = listing_categories();
foreach ($list as $key => $value) {
echo ' <option value='.$key.'>'.$value.'</option>';
}
?>
</select>
</td>
<td><input type="text" name="description_materiel#1" id="description_materiel#1" class="form-control" value=""></td>
<td><input type="text" name="buy_date#1" id="buy_date#1" class="date form-control" value=""></td>
<td>
<select name="etat#1" id="etat#1" class="form-control" value="">
<?php
$list = listing_etats();
foreach ($list as $key => $value) {
echo ' <option value='.$key.'>'.$value.'</option>';
}
?>
</select>
</td>
</tr>
</tbody>
</table>
如何在 jQuery 中添加一行?
var num= parseInt($('#matos tr:last').prop("id").split('#')[1])+1;
$('#matos tr:last').after('<tr id="ligne#'+num+'">'+
'<td><input type="text" name="materiel#'+num+'" id="materiel#'+num+'" class="form-control" value=""></td>'+
'<td><select name="fournisseur#'+num+'" id="fournisseur#'+num+'" class="form-control" value="">'+
opt_fournisseurs+
'</select></td>'+
'<td><input type="text" name="num_serie#'+num+'" id="num_serie#'+num+'" class="form-control" value=""></td>'+
'<td><select name="categorie#'+num+'" id="categorie#'+num+'" class="form-control" value="">'+
opt_categories+
'</select></td><td><input type="text" name="description_materiel#'+num+'" id="description_materiel#'+num+'" class="form-control" value=""></td>'+
'<td><input type="text" name="buy_date#'+num+'" id="buy_date#'+num+'" class="date form-control" value=""></td>'+
'<td><select name="etat#1" id="etat#1" class="form-control" value="">'+
opt_states+
'</select></td></tr>');
$('#nbLignes').val(num);
我正在尝试使用 PHP:
$_POST['materiel#2'] // doesn't work
$_POST['materiel#1'] // works ! ( because first line ! )
我读过一些问题,如果它们不在 table tr td 中,表格就不起作用......但就我而言,它们是......有什么问题?
【问题讨论】:
-
如果你检查 jquery 添加的材料输入框的名称而不是你得到的??
-
当您转储 (
var_dump())$_POST中的值时会发生什么?您是否看到默认情况下不存在的任何其他类别或值? -
打印你的 $_POST,你就会明白哪里出了问题。
-
是的,我得到了所有的 '#1' 但我得到了其他行的错误
Undefined index: [nameOfInput]#NumberOfLine...好像数据不会发送 -
@Seba99 优点是您不必跟踪数字(
categorie#1、materiel#2)等。它只是将具有该名称的所有内容转换为具有索引的数组。看看这个答案以获得一个明确的用法示例:stackoverflow.com/a/1010970/1294864
标签: javascript php jquery html