简体   繁体   中英

How to get all selected values from multiple select option?

I have a contact form with multiple select option. But there is only 1 value appear in the email after the contact form submitted. Would like to look for solution to get this work.

/ * My code begins * /

$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");
}

<-- HTML Begins here -->

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

/ * Code Ends * /

This is the php code in the file name "process.php" to process the form. The value of "$problems" is a multiple select option. I tried to select a few choices when filling out the form, but at the end, there is only 1 single value showing in the email. Can someone help? What code should i add to make it work? Truly appreciate if someone could help. Thanks!

Use name as like problems[] instead of 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;
}
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM