我已经构建了一个HTML表单,其中包含用于为多个输入添加行的按钮。无论添加多少行,我都希望用输入数据通过电子邮件发送所有行。到目前为止,我收到了电子邮件,但它只有一行数据和所有输入字段都在说“数组”,我收到“第34行的数组到字符串转换”的通知。 “第41行的数组到字符串转换”
这甚至可能吗?
HTML表单代码:
<form action="Email.php" method="POST">
<table id="2HL" name="Pass">
<tbody>
<tr>
<td><font style="color: #b22222; font-size:120%">Date</font></td>
<td><input type="datetime" name="Date"></td>
</tr>
<tr>
<td><font style="color: #b22222; font-size:120%">Team Lead</font></td>
<td><input type="text" name="Team_Lead"></td>
</tr>
<tr>
<td><font style="color: #00008b; font-size:120%">End of Shift Information:</font></td>
</tr>
<tr>
<table id="Cellinfo">
<tbody>
<tr>
<td Type="text" name="Cell"><font style="color: #b22222; font-size:100%">CELL</font></td>
<td Type="text" name="Goal"><font style="color: #b22222; font-size:100%">GOAL</font></td>
<td Type="text" name="Comp"><font style="color: #b22222; font-size:100%">COMP</font></td>
<td Type="text" name="LTD"><font style="color: #b22222; font-size:100%">LTD</font></td>
<td Type="text" name="WET_SKU"><font style="color: #b22222; font-size:100%">WET SKU</font></td>
</tr>
<tr id="clone">
<td><input type="text" name="Cell[]"></td>
<td><input type="text" name="Goal[]"></td>
<td><input type="text" name="Comp[]"></td>
<td><input type="text" name="LTD[]"></td>
<td><input type="text" name="WET_SKU[]"></td>
</tr>
</tbody>
</table>
<input type="button" onclick="cloneRow()" value="ADD ROW" /><br>
</tr>
<tr>
<td><font style="color: #00008b; font-size:120%">Impediment Notes:</font></td>
</tr>
<tr>
<table id="impediment">
<tbody>
<tr>
<td Type="text" name="Cell0"><font style="color: #b22222; font-size:100%">CELL</font></td>
<td Type="text" name="SKU0"><font style="color: #b22222; font-size:100%">SKU</font></td>
<td Type="text" name="Part0"><font style="color: #b22222; font-size:100%">PART #</font></td>
<td Type="text" name="Impediment0"><font style="color: #b22222; font-size:100%">IMPEDIMENT TYPE</font></td>
<td Type="text" name="QTYadj0"><font style="color: #b22222; font-size:100%">QTY ADJUSTED</font></td>
<td Type="text" name="Partloc0"><font style="color: #b22222; font-size:100%">PART LOCATION</font></td>
<td Type="text" name="Comments0"><font style="color: #b22222; font-size:100%">TEAM LEAD COMMENTS</font></td>
</tr>
<tr id="clone1">
<td><input type="text" name="Cella[]"></td>
<td><input type="text" name="SKU[]"></td>
<td><input type="text" name="Part[]"></td>
<td><input type="text" name="Impediment[]"></td>
<td><input type="text" name="QTYadj[]"></td>
<td><input type="text" name="Partloc[]"></td>
<td><input type="text" name="Comments[]" size="75"></td>
</tr>
</tbody>
</table>
<input type="button" onclick="cloneimpediment()" value="ADD ROW" /><br>
</tr>
</tbody>
</table>
<p>
<input type="submit" value="Email Form">
</P>
</form>
添加行的Java代码:
<script type="text/javascript">
function cloneRow()
{
var row = document.getElementById("clone"); // find row to copy
var table = document.getElementById("Cellinfo"); // find table to append to
var clone = row.cloneNode(true); // copy children too
clone.id = "clone"; // change id or other attributes/contents
table.appendChild(clone); // add new row to end of table
}
function cloneimpediment()
{
var row = document.getElementById("clone1"); // find row to copy
var table = document.getElementById("impediment"); // find table to append to
var clone = row.cloneNode(true); // copy children too
clone.id = "clone1"; // change id or other attributes/contents
table.appendChild(clone); // add new row to end of table
}
</script>
PHP代码:
<?php foreach($_POST as $key => $value){
$Date = $_POST['Date'];
$Team_Lead = $_POST['Team_Lead'];
$Cell = $_POST['Cell'];
$Goal = $_POST['Goal'];
$Comp = $_POST['Comp'];
$LTD = $_POST['LTD'];
$WET_SKU = $_POST['WET_SKU'];
$Cella = $_POST['Cella'];
$SKU = $_POST['SKU'];
$Part = $_POST['Part'];
$Impediment = $_POST['Impediment'];
$QTYadj = $_POST['QTYadj'];
$Partloc = $_POST['Partloc'];
$Comments = $_POST['Comments'];
}
$email_from = 'TestTeamLead@moen.com';
$email_subject = "Pass Down Test";
$email_body = "<html><body>";
$email_body .= '<table border="1">';
$email_body .= "<tr><td>Date</td><td>$Date</td></tr>";
$email_body .= "<tr><td>Team Lead</td><td>$Team_Lead</td></tr>";
$email_body .= "</table>";
$email_body .= "<br>";
$email_body .= "END OF SHIFT INFORMATION:";
$email_body .= "<br>";
$email_body .= '<table border="1">';
$email_body .= '<tr><td>Cell</td><td>Goal</td><td>Comp</td><td>LTD</td><td>WET SKU</td></tr>';
$email_body .= "<tr><td>$Cell</td><td>$Goal</td><td>$Comp</td><td>$LTD</td><td>$WET_SKU</td></tr>";
$email_body .= "</table>";
$email_body .= "<br>";
$email_body .= "IMPEDIMENT NOTES:";
$email_body .= "<br>";
$email_body .= '<table border="1">';
$email_body .= '<tr><td>Cell</td><td>SKU</td><td>PART #</td><td>ImpedimentType</td><td>QTY Adjusted</td><td>Part Location</td><td>TEAM LEAD Comments</td></tr>';
$email_body .= "<tr><td>$Cella</td><td>$SKU</td><td>$Part</td><td>$Impediment</td><td>$QTYadj</td><td>$Partloc</td><td>$Comments</td></tr>";
$email_body .= "</table>";
?>
答案 0 :(得分:0)
好吧,我想这里foreach($_POST as $key => $value)
想要遍历所有HTML表行。但问题是,您在服务器上的确是您在客户端上指定的内容。
试试print_r($_POST)
,这样您就可以了解到服务器的数据。您应该遍历您的随机密钥或重写客户端代码以获得符合的PHP脚本。
答案 1 :(得分:0)
第31行和第41行的代码是数组,你应该迭代for循环以在html中显示它们,这就是你得到数组通知的原因。为什么你的输入字段名称属性设置为array []?