我很难理解从表单中提取信息并保存到服务器上的 csv 的脚本。问题是,我有一个包含多个表格的表格,在这些表格中有一个“+”按钮来添加另一行。我正在使用 jquery 来做到这一点。这工作正常,还将行数保存到隐藏输入中,并将 _0、_1、_2 分配给 textarea 名称。
我真的很困惑如何根据用户添加的行数使用 PHP 为这些变量动态分配变量。这是我的表格:
<table style="width:100%;" id="directEmployees">
<tbody>
<tr>
<td>Name</td>
<td>Time Start</td>
<td>Time Finish</td>
<td>Job Description</td>
<td>Plant/Machinery Issued/Used</td>
<td>P.P.E Issued?</td>
<td>Materials Issued/Used</td>
</tr>
<tr>
<td width="20%"><textarea style="width:100%;" name="directName_0" id="directName_0"></textarea></td>
<td width="10%"><textarea style="width:100%;" name="directTimeStart_0" id="directTimeStart_0"></textarea></td>
<td width="10%"><textarea style="width:100%;" name="directTimeEnd_0" id="directTimeEnd_0"></textarea></td>
<td width="20%"><textarea style="width:100%;" name="directJob_0" id="directJob_0"></textarea></td>
<td width="15%"><textarea style="width:100%;" name="directPlant_0" id="directPlant_0"></textarea></td>
<td width="10%"><textarea style="width:100%;" name="directPPE_0" id="directPPE_0"></textarea></td>
<td width="15%"><textarea style="width:100%;" name="directMaterials_0" id="directMaterials_0"></textarea></td>
</tr>
</tbody>
</table>
<h2 id="addEmployee" style="cursor:pointer;">+</h2>
<button type="submit">Submit</button>
</form>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
var additional_rows = 0;
$('#addEmployee').click(function() {
additional_rows = additional_rows + 1;
$('#rowsEmployee').val(additional_rows);
var addTable = '<tr><td width="20%"><textarea style="width:100%;" name="directName_' + additional_rows + '" id="directName_' + additional_rows + '"></textarea></td><td width="10%"><textarea style="width:100%;" name="directTimeStart_' + additional_rows + '" id="directTimeStart_' + additional_rows + '"></textarea></td><td width="10%"><textarea style="width:100%;" name="directTimeEnd_' + additional_rows + '" id="directTimeEnd_' + additional_rows + '"></textarea></td><td width="20%"><textarea style="width:100%;" name="directJob_' + additional_rows + '" id="directJob_' + additional_rows + '"></textarea></td><td width="15%"><textarea style="width:100%;" name="directPlant_' + additional_rows + '" id="directPlant_' + additional_rows + '"></textarea></td><td width="10%"><textarea style="width:100%;" name="directPPE_' + additional_rows + '" id="directPPE_' + additional_rows + '"></textarea></td><td width="15%"><textarea style="width:100%;" name="directMaterials_' + additional_rows + '" id="directMaterials_' + additional_rows + '"></textarea></td></tr>';
$('#directEmployees tbody').append(addTable);
});
});
</script>
任何帮助将不胜感激。