【问题标题】:PHP Submission Form to Email Check BoxesPHP 提交表单到电子邮件复选框
【发布时间】:2011-08-01 10:41:47
【问题描述】:

大家好,我是 php 新手,我正在制作人们在线预订的提交表单。

我的表单工作正常,但我想为附加功能添加复选框,然后在发送给用户和我自己的确认电子邮件中注明这些附加功能。

<tr>
    <td height="10" align="right" class="align_right">Deodoriser:&nbsp;</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):&nbsp;</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:&nbsp;</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:&nbsp;</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:&nbsp;</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:&nbsp;</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";    

感谢您提供的任何帮助/建议,我在这里查看了所有类似的问题,并尝试了几天让它正常工作,但无法做到。

【问题讨论】:

    标签: php mysql email forms


    【解决方案1】:

    您可以使用复选框并将值存储在数组中:

    <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;
    }
    

    【讨论】:

      【解决方案2】:

      您在 HTML 表单中将它们创建为输入类型复选框。所有的复选框都应该具有相同的名称,最后用方括号表示一个 PHP 数组:

      <input type="checkbox" name="options[]" value="value"/>
      

      当您提交表单时,所有选中复选框的值都将作为您给它的名称下的 GET 或 POST 超全局数组中的数组提供,因此您可以像这样循环:

      $options = $_GET['options'];
      foreach ($options as $option) {
        // $option will now hold the "value" of the checkbox being processed
      }
      

      【讨论】:

        【解决方案3】:

        而不是您的strip_tags(str_replace()) 只需输入字符串即可。例如

        $deodoriser = !empty($_REQUEST["deodoriser"]) ? 'Deodoriser' : '';
        

        在您的 html 中设置 type="checkbox"

        如果要预先检查,您需要在 HTML 中为每个设置设置 checked="checked",而不是 value=

        【讨论】:

        • 抱歉我贴错了,我已经把所有的复选框都改成了复选框。这会通过电子邮件发送复选框的结果吗?
        • 如果复选框被选中,那么它将位于 $_REQUEST 数组中,您可以从那里将其添加到电子邮件中。您的电子邮件中的复选框似乎没有包含任何内容。
        • 我的错误,我添加了正确的电子邮件,因为我粘贴了错误的电子邮件。
        • 将行更改为$deodoriser = !empty($_REQUEST["deodoriser"]) ? 'Yes' : 'No';,它会更好地与您的电子邮件代码配合使用。
        【解决方案4】:

        将输入类型设置为“复选框”。

        【讨论】:

          猜你喜欢
          • 2013-09-16
          • 2015-11-09
          • 1970-01-01
          • 1970-01-01
          • 2018-11-05
          • 1970-01-01
          • 2020-09-05
          • 2014-02-27
          • 1970-01-01
          相关资源
          最近更新 更多