电子邮件表单的php复选框数组

时间:2013-01-27 10:27:55

标签: php email

我是stackoverflow的新手,但在尝试了很多方法后,我无法理解这封电子邮件表单。表单工作正常,但我试图添加4个可选的复选框,以便客户可以勾选,以便我们知道他们感兴趣的包。我认为我已经正确设置了前端:< / p>

      <p><label for="author">Full Name:</label><br />
    <input type="text" name="cf_name" class="details" tabindex="1" /></p>

<p><label for="telephone">Telephone:</label><br />
    <input type="text" name="cf_telephone" class="details" tabindex="2" /></p>

<p><label for="email">E-mail:</label><br />
         <input type="text" name="cf_email" class="details" tabindex="3" /></p>

<p><label for="package">Package Type:</label><br />
   <input type="checkbox" name="cf_package[]" class="package" value="Business English Classes" tabindex="4" /> Business English Classes<br />

        <input type="checkbox" name="cf_package[]" class="package" value="English Conversation Classes" tabindex="4" /> English Conversation Classes<br />

        <input type="checkbox" name="cf_package[]" class="package" value="Exam Preparation Classes" tabindex="4" /> Exam Preparation Classes<br />

        <input type="checkbox" name="cf_package[]" class="package" value="Writing Skills Classes" tabindex="4" /> Writing Skills Classes
</p>

        <p><label for="message">Questions/Comments:</label><br />
<textarea type="text" name="cf_message" class="questions" tabindex="8"></textarea></p>

<p style="padding-top:10px;"><input type="submit" name="submit" value="Submit" class="button" tabindex="9" /> <input type="reset" name="submit" value="Clear" class="button" tabindex="10" /></p>

<p><label for="author">Full Name:</label><br /> <input type="text" name="cf_name" class="details" tabindex="1" /></p> <p><label for="telephone">Telephone:</label><br /> <input type="text" name="cf_telephone" class="details" tabindex="2" /></p> <p><label for="email">E-mail:</label><br /> <input type="text" name="cf_email" class="details" tabindex="3" /></p> <p><label for="package">Package Type:</label><br /> <input type="checkbox" name="cf_package[]" class="package" value="Business English Classes" tabindex="4" /> Business English Classes<br /> <input type="checkbox" name="cf_package[]" class="package" value="English Conversation Classes" tabindex="4" /> English Conversation Classes<br /> <input type="checkbox" name="cf_package[]" class="package" value="Exam Preparation Classes" tabindex="4" /> Exam Preparation Classes<br /> <input type="checkbox" name="cf_package[]" class="package" value="Writing Skills Classes" tabindex="4" /> Writing Skills Classes </p> <p><label for="message">Questions/Comments:</label><br /> <textarea type="text" name="cf_message" class="questions" tabindex="8"></textarea></p> <p style="padding-top:10px;"><input type="submit" name="submit" value="Submit" class="button" tabindex="9" /> <input type="reset" name="submit" value="Clear" class="button" tabindex="10" /></p>

我的后端脚本如下:

希望我在网站上也能正确显示这一点。

1 个答案:

答案 0 :(得分:0)

选定的'包'将作为数组发送到服务器,而不是字符串,因为您使用数组符号([])并使用复选框,人们可以选择多个包。

您可能希望将数组转换为以逗号分隔的字符串,并显示用户选择的包:

$field_package = implode(', ', $_POST['cf_package']); 

然后:

$body_message .= "Package Type(s): ".$field_package."\n";

如果只允许选择一个选项,您可以考虑使用单选按钮代替复选框。