如何从多个选择选项中获取所有选定的值?

时间:2014-12-20 11:37:38

标签: php contact-form

我有一个带有多个选择选项的联系表格。但在提交联系表单后,电子邮件中只显示1个值。想找到解决方案来完成这项工作。

/ *我的代码开始* /

$title = $_POST['title'];
$contactperson = $_POST['contactperson'];
$phonenumber = $_POST['phonenumber'];
$emailaddress = $_POST['emailaddress'];
$companyname = $_POST['companyname'];
$brand = $_POST['brand'];
$machinemodel = $_POST['machinemodel'];
$serialnumber = $_POST['serialnumber'];
$problems = $_POST['problems']; <--- this is multiple selection values
$inquiry = $_POST['inquiry'];
$security = $_POST['security'];
$from = "YT Copier";
$to = "mail@jornes.com";
$subject = "Admin, someone submitted service request form.";
$message = "Admin, someone has submitted service request form. Details are as follow: \n\nName: $title $contactperson\n\nPhone Number: $phonenumber\n\nEmail Address: $emailaddress\n\nCompany Name: $companyname\n\nMachine Brand:\n$brand\n\nMachine Model: $machinemodel\n\nSerial Number: $serialnumber\n\nProblem Facing: $problems\n\nMessage: $inquiry";

if ($security=="13") {
   mail($to, $subject, $message, $from);
   header("Location:/supports/submit-service-request/?s=s");
}

else {
   header("Location:/supports/submit-service-request/?s=e");
}

&lt; - HTML从这里开始 - &gt;

<select multiple="multiple" name='problems' id='problems' class="inpBox multiple" size='8' >
        <option value="Cannot Copy">Cannot Copy</option>
        <option value="Cannot Print">Cannot Print</option>
        <option value="Cannot Print">Cannot Scan</option>
        <option value="Cannot Fax">Cannot Fax</option>
        <option value="Lines Appear When Printing/Copying">Lines Appear When Printing/Copying</option>
        <option value="Scan to Email Failed">Scan to Email Failed</option>
        <option value="Toner Low/Empty">Toner Low/Empty</option>
        <option value="Others">Others</option>
</select>

/ *代码结束* /

这是文件名中的php代码&#34; process.php&#34;处理表格。 &#34; $ problems&#34;的价值是一个多选选项。我在填写表单时尝试选择一些选项,但最后,电子邮件中只显示了一个单一值。有人可以帮忙吗?我应该添加什么代码才能使其正常工作?真的很感激,如果有人可以帮忙。谢谢!

1 个答案:

答案 0 :(得分:4)

使用名称problems[]代替problems

//Simple Form and getting the values

<form name="s" method="post" action="" >
 <select multiple="multiple" name='problems[]' id='problems' class="inpBox multiple" size='50' style="height:150px;" >
        <option value="Cannot Copy">Cannot Copy</option>
        <option value="Cannot Print">Cannot Print</option>
        <option value="Cannot Print">Cannot Scan</option>
        <option value="Cannot Fax">Cannot Fax</option>
        <option value="Lines Appear When Printing/Copying">Lines Appear When Printing/Copying</option>
        <option value="Scan to Email Failed">Scan to Email Failed</option>
        <option value="Toner Low/Empty">Toner Low/Empty</option>
        <option value="Others">Others</option>
</select>
<input type="submit" name="submit" value="submit" />
</form>


<?php 
if (isset($_POST['submit'])) {
    $problems =  implode(',', $_POST['problems']);
    echo $problems;
}
?>