CodeIgniter Forums

Full Version: Having trouble printing all the values from an array
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a form with a checkbox so the user can select multiple items from the checkbox, the submission and everything works ok, just need help getting the values from the checkbox. I realize this isnt exactly CodeIgniter help but any help you can give is much appreciated...

Here is my form code for the checkbox. I'm just trying to get the $productSheets variable to print all the values in the email at the bottom...

        <label style="margin-top:10px;" for="checkbox" id="productSheets">Which products are you interested in?</label>
        <input type="checkbox" name="productSheets[]" value="lidar"> LiDAR - IR Laser Array Field<br>
        <input type="checkbox" name="productSheets[]" value="nui"> NUI-IR Laser Array Chip<br>
        <input type="checkbox" name="productSheets[]" value="optical"> Optical Solutions

and here is the code from my process.php file. The other variables display fine.


//prepare mail headers
$to = "[email protected]";
$from = "[email protected]";
$headers = "From: Corp <$from>";
$subject = "Product Sheet Request";
//prepare request form variables
$firstName = $_REQUEST['firstName'];
$lastName = $_REQUEST['lastName'];
$email = $_REQUEST['email'];
$phone = $_REQUEST['phone'];
$affiliation = $_REQUEST['affiliation'];
$interest = $_REQUEST['interest'];
if($interest == 'inclusion'){
   $interest = 'Evaluating for inclusion in product';
} elseif($interest == 'general'){
   $interest = 'Interested in the technology generally';
} elseif($interest == 'research'){
   $interest = 'Performing market research';
} elseif($interest == 'solutions'){
   $interest = 'Looking for competitive solutions';
$referredBy = $_REQUEST['referredBy'];
$additional = $_REQUEST['additional'];
$productSheets = $_REQUEST['productSheets'];

//prepare message body
$body =
"A user has requested product sheet(s). Please review their information and respond:\n
   First Name: ".$firstName."\n
   Last Name: ".$lastName."\n
   Email: ".$email."\n
   Phone Number: ".$phone."\n
   Affiliation: ".$affiliation."\n
   Reason for Interest: ".$interest."\n
   Referred By: ".$referredBy."\n
   Additional Questions/Comments: ".$additional."\n
   Product Sheet(s) Requested: ".$productSheets."\n
This message was sent automatically from the Product Sheet Requests form on the website.

//send the message/info to personel
$send = mail($to, $subject, $body, $headers);

Since $productSheets should be an array, you will have to loop through it to extract the values. print_r($productSheets) should work to verify that the data has been passed to the variable properly, but it's unlikely that it will give you the output you want for display to the end-user.
$checkboxes = $this->input->post('productSheets');

foreach($checkboxes as $cb)
  echo "$cb<br>";