【发布时间】:2013-05-13 05:21:22
【问题描述】:
我有一个如下表格,它允许用户通过添加更多按钮添加更多输入字段。我的问题是如何在 POST 中检索数组并将它们回显出来。如您所见,我有两个名称为 product[] 和 quantity[] 的输入字段(可以添加更多字段)。我必须使用 foreach 循环获取字段的值并将其存储在要在 mail() 中使用的变量 $message 中。我已经尝试了一个 for each 循环和我的 for each 循环代码,如下所示
$product = $_POST['product'];
$quantity = $_POST['quantity'];
foreach($product as $value)
{
$message = "<html><head>
<title></title>
</head>
<body>
<table>
<tr>
<td>".$value."";
}
foreach($quantity as $value)
{
$message.=" </td>
<td>".$value."</td>
</tr>
</table>
</body>
</html>";
}
我的输入表单
<form id="quick_post" method="post">
<table id="input_fields">
<tr>
<td><input class="orderinput" type="text" name="product[]" /></td>
<td><input class="orderquan" type="text" name="quantity[]" size="1" maxlength="3" /></td>
</tr>
</tr>
</table>
<input class="more" type="button" value="Addmore" name="addmore" /> // a jquery script is processed on click to add more fields.
<input class="send" type="submit" value="Send" name="send" /></form>
对此的输出是我只打印了第一行产品,而剩下的行只打印或回显了数量。如下
Product Name Quantity
aaaaaa 22
33
【问题讨论】:
-
你的循环中有头部/标题标签等,你不希望这些重复
-
我的尝试是发送 html 邮件。我想,我可以移动循环中的 html 和 head 标签。