简体   繁体   中英

Processing multi-select list box to design an email layout

I am currently trying to modify a contact form created by someone else. The current form processing php file uses a function mentioned in this article: http://www.gerd-riesselmann.net/archives/2005/09/sending-spam-through-contact-forms .

Here is the code segment where it formats the email to be sent out.

    if($_POST["txtEmail"]!=""){
    $xm="info@xxx.co.uk";
    $pem=$_POST["txtEmail"];
    $sb="Chauffer Inquiry";
    $txt='  <table border="1" cellpadding="3" cellspacing="0" style="border-collapse: collapse">
        <tr>
          <td align="right"><strong>Name:</strong></td>
          <td width="250">'.preprocessHeaderField($_POST["txtName"]).'</td>
        </tr>
<tr>
      <td align="right"><strong>Date of booking:</strong></td>
      <td width="250">'.preprocessHeaderField($_POST["date"]).'</td>
    </tr>

My problem is this handling a list box with multi-select capability within this formatting section. I have created it correctly in the form using an array, but I still can't figure out how to process it within this code. Could someone explain how to include a for statement in here? I am capturing the number of selected items these two statements, before the if statement.

$aCars = $_POST['Cars'];
$nCars = count($aCars);

I did look everywhere but couldn't find a way to embed a for statement to the above code. Please go easy on me as my php skills are not that great.

Assuming everything works ($aCars and $nCars) have values and you want to know which were selected.

You need to convert the array to a sting so it can be printed. Have a look at the implode function. That function allows you to 'glue' array elements together into a string.

$carString = implode(",", $aCars); // $carString will be 'Car1,Car2,Car3'

From there you can append it to $txt.

$txt .= "<tr><td>Car names</td><td>".$carString. "</td></tr>";

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