2011-04-08 104 views
0

嗨,大家好我是新來的PHP和即時通訊作出提交表格,人們在線預訂。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";  

感謝所有幫助/意見,我已經完成了所有類似的問題在這裏看了一下,嘗試了幾天才能得到它的工作,只是不能做它。

回答

1

您可以使用複選框和值存儲在一個數組:

<input type="checkbox" name="extras[]" value="Deodoriser" /> 
<input type="checkbox" name="extras[]" value="Carpet" /> 
<input type="checkbox" name="extras[]" value="Furniture" /> 

然後循環通過$ _ POST [「附加」]數組輸出值

foreach($_POST['extras'] as $extra) 
{ 
    $message .="<br />Extra: ".$extra; 
} 
0

將輸入類型設置爲「複選框」。

0

而不是你的strip_tags(str_replace())只要放在字符串中。例如

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

隨着設置type="checkbox"在您的HTML。

而不是value=如果你想預先檢查,你需要在你的HTML中設置checked="checked"

+0

對不起,我貼錯了,我已經改變了所有複選框已鍵入複選框。這封電子郵件是否會顯示覆選框的結果? – Simon 2011-04-08 11:30:25

+0

如果複選框被選中,則它將位於$ _REQUEST數組中,然後可以將其添加到電子郵件中。它看起來並不像您在電子郵件中包含任何複選框。 – 2011-04-08 11:32:42

+0

我的錯誤,我添加了正確的電子郵件,因爲我粘貼了錯誤的電子郵件。 – Simon 2011-04-08 11:37:41

1

您可以在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 
}