我有一个带有一组输入(用于收费)的表格(发票)。
<tr>
<td><label>Description:</label></td>
<td><input type="text name="description[]" value="'.$labor->description.'" /></td>
<td><label>Hours:</label></td>
<td><input type="text name="hours[]" value="'.$labor->hours.'" size="2" /></td>
<td><label>Rate:</label></td>
<td><input type="text name="rate[]" value="'.$labor->rate.'" size="2" /></td>
<input type="hidden" name="labor_id[]" value="'.$labor->id.'" />
</tr>
我正在使用 javascript 函数来添加另一组这些输入。
function moreLabor(table) {
var table = document.getElementById(table);
var row = table.insertRow(-1);
var descriptionLabel = document.createElement("label");
descriptionLabel.innerHTML="Description:";
var description = document.createElement("input");
description.name = "description[]";
description.type = "text";
var td1 = row.insertCell(-1);
var td2 = row.insertCell(-1);
td1.appendChild(descriptionLabel);
td2.appendChild(description);
var hoursLabel = document.createElement("label");
hoursLabel.innerHTML="Hours:";
var hours = document.createElement("input");
hours.name = "hours[]";
hours.type = "text";
hours.size = 2;
hours.value = 1;
var td1 = row.insertCell(-1);
var td2 = row.insertCell(-1);
td1.appendChild(hoursLabel);
td2.appendChild(hours);
var rateLabel = document.createElement("label");
rateLabel.innerHTML="Rate:";
var rate = document.createElement("input");
rate.name = "rate[]";
rate.type = "text";
rate.size = 2;
rate.value = 25;
var td1 = row.insertCell(-1);
var td2 = row.insertCell(-1);
td1.appendChild(rateLabel);
td2.appendChild(rate);
var remove = document.createElement("input");
remove.type = "button";
remove.value = "Remove";
remove.onclick = function () {
var parent = this.parentNode.parentNode; //get the row node
table.deleteRow(parent.rowIndex); //Delete the row index behind it.
};
var td1 = row.insertCell(-1).appendChild(remove);
}
如您所见,我在重复输入名称后使用 [ ]。问题是 POST 只返回每个值的最后一组。我查看了原始查询字符串,它也只包含最后一组值。费率、小时数和描述作为数组返回,但每个仅设置 1 个值。如何填充整个 POST 数组?