大家好,我是 php 新手,我正在制作一个提交表单供人们在线预订。
我的表单工作正常,但我想添加额外的复选框,然后在发送给用户和我自己的确认电子邮件中注明这些额外的内容。
<tr>
<td height="10" align="right" class="align_right">Deodoriser: </td>
<td>
<input type="text" name="deodoriser" id="deodoriser" value="<?php echo $deodoriser?>" onchange="checkFieldBack(this)"/>
</td>
</tr>
<tr>
<td height="30" align="right" class="align_right">Carpet Protector (5 litre): </td>
<td>
<input type="text" name="carpet" id="carpet" value="<?php echo $carpet?>" onchange="checkFieldBack(this)"/>
</td>
</tr>
<tr>
<td height="30" align="right" class="align_right">Carpet Repair Tools: </td>
<td>
<input type="text" name="carpetrepair" id="carpetrepair" value="<?php echo $carpetrepair?>" onchange="checkFieldBack(this)"/>
</td>
</tr>
<tr>
<td height="30" align="right" class="align_right">Furniture Moving Equipment: </td>
<td>
<input type="text" name="furniture" id="furniture" value="<?php echo $furniture?>" onchange="checkFieldBack(this)"/>
</td>
</tr>
<tr>
<td height="30" align="right" class="align_right">Furniture Tabs: </td>
<td>
<input type="text" name="tabs" id="tabs" value="<?php echo $tabs?>" onchange="checkFieldBack(this)"/>
</td>
</tr>
<tr>
<td height="30" align="right" class="align_right">Urine Decontamination Treatment: </td>
<td>
<input type="text" name="urine" id="urine" value="<?php echo $urine?>" onchange="checkFieldBack(this)"/>
</td>
</tr>
我想制作这些复选框而不是文本。 这些是变量
$deodoriser = (!empty($_REQUEST["deodoriser"]))?strip_tags(str_replace("'","`",$_REQUEST["deodoriser"])):'';
$carpet = (!empty($_REQUEST["carpet"]))?strip_tags(str_replace("'","`",$_REQUEST["carpet"])):'';
$carpetrepair = (!empty($_REQUEST["carpetrepair"]))?strip_tags(str_replace("'","`",$_REQUEST["carpetrepair"])):'';
$furniture = (!empty($_REQUEST["furniture"]))?strip_tags(str_replace("'","`",$_REQUEST["furniture"])):'';
$tabs = (!empty($_REQUEST["tabs"]))?strip_tags(str_replace("'","`",$_REQUEST["tabs"])):'';
$urine = (!empty($_REQUEST["urine"]))?strip_tags(str_replace("'","`",$_REQUEST["urine"])):'';
这是确认电子邮件
$message .="Name: ".$name;
$message .="<br />Email: ".$email;
$message .="<br />Phone: ".$phone;
$message .="<br />Quantity: ".$qty;
$message .="<br />Address: ".$comments;
$message .="<br />Drop off Time: ".$dropoff;
$message .="<br />Machine: ".$eventInf[0].;
$message .="<br />Deodoriser: ".$deodoriser;
$message .="<br />Carpet Protector: ".$carpet;
$message .="<br />Carpet Repair Tools: ".$carpetrepair;
$message .="<br />Furniture Moving Equipment: ".$furniture;
$message .="<br />Furniture Tabs: ".$tabs;
$message .="<br />Urine Decontamination Treatment: ".$urine;
$message .="<br />Booking date: ".$eventInf[2]."<br />";
$message .="<br />Reservation Status: Not Confirmed<br />";
$message .="<br /><br />Kind Regards, <br /> ".$_SERVER['HTTP_HOST']." Website";
感谢您的任何帮助/建议,我已经浏览了这里所有类似的问题,并尝试了几天让它工作,但就是做不到。
最佳答案
您可以使用复选框并将值存储在数组中:
<input type="checkbox" name="extras[]" value="Deodoriser" />
<input type="checkbox" name="extras[]" value="Carpet" />
<input type="checkbox" name="extras[]" value="Furniture" />
然后循环遍历 $_POST['extras'] 数组来输出值
foreach($_POST['extras'] as $extra)
{
$message .="<br />Extra: ".$extra;
}
关于PHP 提交表单到电子邮件复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5594294/