oceanreaction Posted May 25, 2010 Share Posted May 25, 2010 I've been doing a lot of research on why I keep getting the word "array" instead of what the person actually wants from the "request information" form I am creating with html/php. Here's my HTML: <p>I am Interested in:<br> <input name="interest[]" type="checkbox" value="A Storage Shed" />A Storage Shed<br> <input name="interest[]" type="checkbox" value="A Garage" />A Garage<br> <input name="interest[]" type="checkbox" value="A Gazebo" />A Gazebo<br> <input name="interest[]" type="checkbox" value="Other" />Other<br> <input name="interest[]" type="checkbox" value="I'd like information about financing programs" />I'd like information about financing programs </p> Here's the PHP part relevant to this: $nameField = $_POST['name']; $addressField = $_POST['address']; $cityField = $_POST['city']; $stateField = $_POST['state']; $zipField = $_POST['zip']; $phoneField = $_POST['phone']; $emailField = $_POST['email']; $ownerField = $_POST['owner']; $interestField = $_POST['interest']; if ( isset($_POST['interest']) ) { $_POST['interest'] = implode(', ', $_POST['interest']); //Converts an array into a single string } The results I am getting sent to my email under the "interest" field as marked as "array" instead of what they have actually checked. What else do I need? Quote Link to comment https://forums.phpfreaks.com/topic/202850-please-help-sending-email-from-php-form-checkbox-area-as-array/ Share on other sites More sharing options...
Sergey Popov Posted May 25, 2010 Share Posted May 25, 2010 I think all you need is to move this line to the bottom: $interestField = $_POST['interest']; Right after you implode an array and re-assign value of $_POST['interest'] Quote Link to comment https://forums.phpfreaks.com/topic/202850-please-help-sending-email-from-php-form-checkbox-area-as-array/#findComment-1063063 Share on other sites More sharing options...
oceanreaction Posted May 25, 2010 Author Share Posted May 25, 2010 So like this? That didn't work... $nameField = $_POST['name']; $addressField = $_POST['address']; $cityField = $_POST['city']; $stateField = $_POST['state']; $zipField = $_POST['zip']; $phoneField = $_POST['phone']; $emailField = $_POST['email']; $ownerField = $_POST['owner']; if ( isset($_POST['interest']) ) { $_POST['interest'] = implode(', ', $_POST['interest']); //Converts an array into a single string } $interestField = $_POST['interest']; Quote Link to comment https://forums.phpfreaks.com/topic/202850-please-help-sending-email-from-php-form-checkbox-area-as-array/#findComment-1063066 Share on other sites More sharing options...
kenrbnsn Posted May 25, 2010 Share Posted May 25, 2010 Instead of <?php $interestField = $_POST['interest']; if ( isset($_POST['interest']) ) { $_POST['interest'] = implode(', ', $_POST['interest']); //Converts an array into a single string } ?> Just do <?php $interestField = (isset($_POST['interest']))?implode(',',$_POST['interest']):'No interests indicated'; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/202850-please-help-sending-email-from-php-form-checkbox-area-as-array/#findComment-1063133 Share on other sites More sharing options...
oceanreaction Posted May 25, 2010 Author Share Posted May 25, 2010 Thank you Ken for your answer. I am still getting the word "array" instead of actual data. Quote Link to comment https://forums.phpfreaks.com/topic/202850-please-help-sending-email-from-php-form-checkbox-area-as-array/#findComment-1063144 Share on other sites More sharing options...
premiso Posted May 25, 2010 Share Posted May 25, 2010 Are you sure you are saving and running the right file? Quote Link to comment https://forums.phpfreaks.com/topic/202850-please-help-sending-email-from-php-form-checkbox-area-as-array/#findComment-1063148 Share on other sites More sharing options...
oceanreaction Posted May 25, 2010 Author Share Posted May 25, 2010 Yes, I know I am calling the right php file, everything else works when I use the type="text" method, but not when I use the "checkbox" method. I'm just not sure how to get the values instead of just the word "array" sent to my email. I need that data and don't know how to get it. Quote Link to comment https://forums.phpfreaks.com/topic/202850-please-help-sending-email-from-php-form-checkbox-area-as-array/#findComment-1063152 Share on other sites More sharing options...
premiso Posted May 25, 2010 Share Posted May 25, 2010 How about you post the html form code for us, so we can better help you. Quote Link to comment https://forums.phpfreaks.com/topic/202850-please-help-sending-email-from-php-form-checkbox-area-as-array/#findComment-1063159 Share on other sites More sharing options...
oceanreaction Posted May 25, 2010 Author Share Posted May 25, 2010 Here's my HTML: <form class="appnitro" method="post" action="contactformprocess.php"> <h2>Information Request</h2> <p>Thank you for your interest. Please complete the following information so that we can help serve you better.</p> <p>Name: <br> <input name= "name" class="element text medium" maxlength="255" value=""/> </p> <p>Street Address <br> <input name="address" class="element text medium" value="" type="text"><br> City <br> <input name="city" class="element text medium" value="" type="text"><br> State <br> <input name="state" class="element text medium" value="" type="text"><br> Zip Code <br> <input name="zip" class="element text medium" value="" type="text"> </p> <p>Daytime Phone <br> <input name="phone" class="element text medium" type="text" maxlength="255" value=""/> </p> <p> E-mail<br> <input name="email" class="element text medium" type="text" maxlength="255" value=""/> </p> <p> I am a:<br> <input name="owner" type="radio" value="homeowner" checked="checked"/>Homeowner <input name="owner" type="radio" value="Builder/Contractor"/>Builder/Contractor </p> <p>I am Interested in:<br> <input name="interest[]" type="checkbox" value="A Storage Shed" /> A Storage Shed<br> <input name="interest[]" type="checkbox" value="A Garage" /> A Garage<br> <input name="interest[]" type="checkbox" value="A Gazebo" /> A Gazebo<br> <input name="interest[]" type="checkbox" value="Other" /> Other<br> <input name="interest[]" type="checkbox" value="I'd like information about financing programs" /> I'd like information about financing programs </p> <li id="li_6" > <label class="description" for="element_6">Additional Comments: </label> <div> <textarea id="element_6" name="element_6" class="element textarea medium"></textarea> </div> </li> <li class="buttons"> <input type="submit" value="Submit" id="submit" class="form-submit" /> </li> </ul> </form> and here's my PHP: (I removed my email address on purpose) <?php /* Subject and Email variables */ $emailSubject = 'Greys Info Request'; $webMaster = 'removed@email.com'; /* Gathering Data Variables */ $nameField = $_POST['name']; $addressField = $_POST['address']; $cityField = $_POST['city']; $stateField = $_POST['state']; $zipField = $_POST['zip']; $phoneField = $_POST['phone']; $emailField = $_POST['email']; $ownerField = $_POST['owner']; $interestField = (isset($_POST['interest']))?implode(',',$_POST['interest']):'No interests indicated'; $commentField = $_POST['element_6']; $body = <<<EOD <br><hr><br> Name: $name <br> Address: $address <br> City: $city <br> State: $state <br> Zip Code: $zip <br> Phone: $phone <br> Email: $email <br> Owner: $owner <br> Interested in: $interest <br> Comments: $element_6 <br> EOD; $headers = "From: $email\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($webMaster, $emailSubject, $body, $headers); /* Results */ $theResults = <<<EOD <html> <head> <title>Greys Woodworks Info Request</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <style type="text/css"> <!-- body { background-color: #f1f1f1; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal; line-height: normal; font-weight: normal; color: #666666; text-decoration: none; } --> </style> </head> <div> <div align="left">Thank you for your interest! Your email will be answered very soon!</div> </div> </body> </html> EOD; echo "$theResults"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/202850-please-help-sending-email-from-php-form-checkbox-area-as-array/#findComment-1063163 Share on other sites More sharing options...
premiso Posted May 25, 2010 Share Posted May 25, 2010 It "should" work. Do a print_r on $_POST['interest'] and see what format it is coming out as, post that information here as well. Quote Link to comment https://forums.phpfreaks.com/topic/202850-please-help-sending-email-from-php-form-checkbox-area-as-array/#findComment-1063165 Share on other sites More sharing options...
oceanreaction Posted May 25, 2010 Author Share Posted May 25, 2010 I've just tried this: $nameField = $_POST['name']; $addressField = $_POST['address']; $cityField = $_POST['city']; $stateField = $_POST['state']; $zipField = $_POST['zip']; $phoneField = $_POST['phone']; $emailField = $_POST['email']; $ownerField = $_POST['owner']; foreach($_POST['interest'] as $value) { $check_msg .= "Checked: $value\n"; } $projectField = $_POST['project']; $contactField = $_POST['contact']; $callField = $_POST['call']; $timeField = $_POST['time']; $commentField = $_POST['commment']; and THAT isn't working either. Still getting "array" sent to my email. Quote Link to comment https://forums.phpfreaks.com/topic/202850-please-help-sending-email-from-php-form-checkbox-area-as-array/#findComment-1063181 Share on other sites More sharing options...
oceanreaction Posted May 25, 2010 Author Share Posted May 25, 2010 For anyone out there in the internets, I got! I got it!!!! This post helped: http://www.kirupa.com/web/php_contact_form3.htm $nameField = $_POST['name']; $addressField = $_POST['address']; $cityField = $_POST['city']; $stateField = $_POST['state']; $zipField = $_POST['zip']; $phoneField = $_POST['phone']; $emailField = $_POST['email']; $ownerField = $_POST['owner']; $projectField = $_POST['project']; $contactField = $_POST['contact']; $callField = $_POST['call']; $timeField = $_POST['time']; $commentField = $_POST['commment']; foreach($_POST['interest'] as $value) { $check_msg .= "Checked: $value\n"; } $body = <<<EOD <br><hr><br> Name: $name <br> Address: $address <br> City: $city <br> State: $state <br> Zip Code: $zip <br> Phone: $phone <br> Email: $email <br> Owner: $owner <br> Interested in: $check_msg <br> Project To Begin: $project <br> Best Way To Contact: $contact <br> Best Time to Call: $call $time <br> Comments: $comment <br> EOD; Quote Link to comment https://forums.phpfreaks.com/topic/202850-please-help-sending-email-from-php-form-checkbox-area-as-array/#findComment-1063228 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.