alexandervj Posted January 19, 2015 Share Posted January 19, 2015 Here is my code... <?php $to = "email@email.com"; //obviously not real $from = "noreply@domain.com"; //obviously not real $firstName = $_REQUEST['firstName']; $headers = "From: $from"; $subject = "Product Sheet Request"; /* $fields = array(); $fields{"firstName"} = "firstName"; $fields{"lastName"} = "lastName"; $fields{"email"} = "email"; $fields{"phone"} = "phone"; $fields{"affiliation"} = "affiliation"; $fields{"interest"} = "interest"; $fields{"productSheets"} = "productSheets"; $fields{"referredBy"} = "referredBy"; $fields{"additional"} = "additional"; */ $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']; $sheets = print_r($productSheets); /* $body = "A user has requested product sheet(s). Please review their information and respond:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } */ $body = "A user has requested product sheet(s). Please review their information and respond:\n First Name: ".$firstName."\r Last Name: ".$lastName."\r Email: ".$email."\r Phone Number: ".$phone."\r Affiliation: ".$affiliation."\r Reason for Interest: ".$interest."\r Referred By: ".$referredBy."\r Additional Questions/Comments: ".$additional."\r Product Sheet(s) Requested: ".$sheets."\n "; $send = mail($to, $subject, $body, $headers); ?> I'm not quite sure how to display the values of the $productSheets array in the email message. Everytime it either outputs "Array" or "1". The $productSheets array is from a checkbox on a form. Everything else is working as expected. Quote Link to comment https://forums.phpfreaks.com/topic/294071-need-help-printing-array/ Share on other sites More sharing options...
requinix Posted January 19, 2015 Share Posted January 19, 2015 The user may have selected multiple values. How would you want, say, 10 values appear? Comma-separated? Bulleted list? If you can answer that then all you have to do is write the code to support it. Quote Link to comment https://forums.phpfreaks.com/topic/294071-need-help-printing-array/#findComment-1503469 Share on other sites More sharing options...
alexandervj Posted January 19, 2015 Author Share Posted January 19, 2015 Yeah I just want to know how to display the values in the email instead of "Array" or "1". I tried print_r as seen above but that produced the output "1" instead of the names of the product sheets. Here is the code for my form if that hepls as well... <form id="contact" name="contact" method="post" novalidate="novalidate"> <h3>Request Product Sheets</h3> <hr style="margin-top:0px; margin-bottom:0px;"/> <p>Please fill out the form below and product sheets will be sent to the email provided.<br/> * indicates a required field.</p> <fieldset> <table> <tr> <td> <input type="text" name="firstName" id="firstName" placeholder="First Name *" value="" required=""> </td> </tr> <tr> <td> <input type="text" name="lastName" id="lastName" placeholder="Last Name *" value="" required=""> </td> </tr> <tr> <td> <input type="text" name="email" id="email" placeholder="Email *" value="" required=""> </td> </tr> <tr> <td> <input type="text" name="phone" id="phone" placeholder="Phone Number *" value=""> </td> </tr> <tr> <td> <input type="text" name="affiliation" id="affiliation" placeholder="Company/Affiliation" value=""> </td> </tr> <tr> <td> <label for="interest" id="interest">To assist us in understanding your interest in our products are you?</label> <input type="radio" name="interest" id="interest" value="inclusion" checked> Evaluating for inclusion in product<br> <input type="radio" name="interest" id="interest" value="general"> Interested in the technology generally<br> <input type="radio" name="interest" id="interest" value="research"> Performing market research<br> <input type="radio" name="interest" id="interest" value="solutions"> Looking for competitive solutions </td> </tr> <tr> <td> <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 </td> </tr> <tr> <td> <input style="margin-top:10px;" type="text" name="referredBy" id="referredBy" placeholder="How did you hear about us?" value=""> </td> </tr> <tr> <td> <textarea name="additional" id="additional" placeholder="Additional questions, comments, or requests:"></textarea> </td> </tr> <tr> <td> <input id="submit" type="submit" name="submit" class="btn btn-primary" value="Send"> </td> </tr> </table> </fieldset> </form> <div id="success"> <span style="text-align: center;"> <p>Your request was sent successfully. We will email you shortly with the information you requested.</p> </span> </div> <div id="error"> <span> <p>Something went wrong, try refreshing and submitting the form again.</p> </span> </div> Quote Link to comment https://forums.phpfreaks.com/topic/294071-need-help-printing-array/#findComment-1503470 Share on other sites More sharing options...
requinix Posted January 20, 2015 Share Posted January 20, 2015 Yeah I just want to know how to display the values in the email instead of "Array" or "1".How do YOU want it to look? You can't tell PHP to make it display a certain way until you can decide what that certain way should be. Quote Link to comment https://forums.phpfreaks.com/topic/294071-need-help-printing-array/#findComment-1503482 Share on other sites More sharing options...
cyberRobot Posted January 21, 2015 Share Posted January 21, 2015 Since you're using the array syntax in the HTML form (ex: name="productSheets[]"), PHP automatically creates an array for you. So there is no need for the square brackets when assigning the information to $productSheets. Try changing this: $productSheets[] = $_REQUEST['productSheets']; To this: $productSheets = $_REQUEST['productSheets']; Now $productSheets can be treated as a regular array. If you want to display the array as a comma-separated list, you could do something like this: print implode(', ', $productSheets); Quote Link to comment https://forums.phpfreaks.com/topic/294071-need-help-printing-array/#findComment-1503615 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.