monstro Posted February 9, 2010 Share Posted February 9, 2010 Hello, i'm trying to send this form to my E-Mail (which works) but i'm also trying to get the checkboxes to appear in the E-mail Body Content. Here is the form on the .net: http://www.jchambo.com/contact.html This form sends all of the information the person fills out to my E-mail and looks like this: Name: name example Website: www.website.com Phone: phone number example Location: location example Position: position example Contact Method: E-Mail Price Range: $0 - $250 Project Length: Within One Week Required Content: Array Message: message example Form Code on Contact.html Page: <form method="POST" action="contact.php"> <table width="908" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td valign="top" width="290" height="50"> <span class="style23">What is your full name? <span class="style26">*</span><br> <input name="Name" type="text" class="style23" size="25"> </span></td> <td valign="top" width="290" height="50"> <span class="style23">What is your phone number? <span class="style26">*</span><br> <input name="Phone" type="text" class="style23" size="25"> </span></td> <td valign="top" width="290" height="50"><span class="style23">What is your location?<br> <input name="Location" type="text" class="style23" size="25"> </span></td> </tr> <tr> <td valign="top" width="290" height="50"><span class="style23">What is your company's name?<br> <input name="Subject" type="text" class="style23" size="25"> </span></td> <td valign="top" width="290" height="50"> <span class="style23">Website URL:<br> <input name="Website" type="text" class="style23" size="25"> </span></td> <td valign="top" width="290" height="50"><span class="style23">What is your e-mail address? <span class="style26">*</span><br> <input name="EmailFrom" type="text" class="style23" size="25"> </span></td> </tr> <tr> <td valign="top" width="290" height="50"><span class="style23">What is your position title?<br> <input name="Position" type="text" class="style23" size="25"> </span> <p><span class="style23">Your site will need:</span></p> <table width="100%" height="126" border="0" cellpadding="0" cellspacing="0"> <tr> <td align="left" valign="middle" class="style23"><span class="style46"> <label> <input type="checkbox" name="RequiredContent[]" value="ASP" /> ASP</label> </span></td> <td align="left" valign="middle" class="style23"><span class="style46"> <label> <input type="checkbox" name="RequiredContent[]" value="JSP" /> JSP</label> </span></td> <td align="left" valign="middle" class="style23"><span class="style46"> <label> <input type="checkbox" name="RequiredContent[]" value="ShoppingCarts" /> Shopping Carts</label> </span></td> </tr> <tr> <td align="left" valign="middle" class="style23"><span class="style46"> <label> <input type="checkbox" name="RequiredContent[]" value="Cplus" /> C/C++</label> </span></td> <td align="left" valign="middle" class="style23"><span class="style46"> <label> <input type="checkbox" name="RequiredContent[]" value="OSCommerce" /> OSCommerce</label> </span></td> <td align="left" valign="middle" class="style23"><span class="style46"> <label> <input type="checkbox" name="RequiredContent[]" value="SQL" /> SQL</label> </span></td> </tr> <tr> <td align="left" valign="middle" class="style23"><span class="style46"> <label> <input type="checkbox" name="RequiredContent[]" value="ColdFusion" /> Cold Fusion</label> </span></td> <td align="left" valign="middle" class="style23"><span class="style46"> <label> <input type="checkbox" name="RequiredContent[]" value="PaypalAPI" /> Paypal API</label> </span></td> <td align="left" valign="middle" class="style23"><span class="style46"> <label> <input type="checkbox" name="RequiredContent[]" value="WebSecurity" /> Web Security</label> </span></td> </tr> <tr> <td align="left" valign="middle" class="style23"><span class="style46"> <label> <input type="checkbox" name="RequiredContent[]" value="eCommerce" /> eCommerce</label> </span></td> <td align="left" valign="middle" class="style23"><span class="style46"> <label> <input type="checkbox" name="RequiredContent[]" value="PHP" /> PHP</label> </span></td> <td align="left" valign="middle" class="style23"><span class="style46"> <label> <input type="checkbox" name="RequiredContent[]" value="WindowsMobile" /> Windows Moible</label> </span></td> </tr> <tr> <td align="left" valign="middle" class="style23"><span class="style46"> <label> <input type="checkbox" name="RequiredContent[]" value="Google" /> Google</label> </span></td> <td align="left" valign="middle" class="style23"><span class="style46"> <label> <input type="checkbox" name="RequiredContent[]" value="PSDs" /> Photoshop PSD's</label> </span></td> <td align="left" valign="middle" class="style23"><span class="style46"> <label> <input type="checkbox" name="RequiredContent[]" value="WordPress" /> WordPress</label> </span></td> </tr> <tr> <td align="left" valign="middle" class="style23"><span class="style46"> <label> <input type="checkbox" name="RequiredContent[]" value="iPhone" /> iPhone</label> </span></td> <td align="left" valign="middle" class="style23"><span class="style46"> <label> <input type="checkbox" name="RequiredContent[]" value="SEO" /> SEO</label> </span></td> <td align="left" valign="middle" class="style23"><span class="style46"> <label> <input type="checkbox" name="RequiredContent[]" value="XML" /> XML</label> </span></td> </tr> </table> <p><span class="style23"><br /> </span></p></td> <td valign="top" width="244" height="10"> <span class="style23">Preferred contact method: </span><span class="style28">*</span><br /> <label> <select name="ContactMethod" size="1" class="style23" id="ContactMethod"> <option value="E-Mail" selected="selected">E-Mail</option> <option value="Phone">Phone</option> </select> </label> <p><span class="style23">Preferred price range: </span><span class="style28">*</span><br /> <label> <select name="PriceRange" size="1" class="style23" id="PriceRange"> <option value="$0 - $250" selected="selected">$0 - $250</option> <option value="$251 - $500">$251 - $500</option> <option value="$501 - $1,000">$501 - $1,000</option> <option value="$1,000 - $2,000">$1,000 - $2,000</option> <option value="$2,001 or Higher">$2,001 or Higher</option> </select> </label></p> <p><span class="style23">When do you need your project done? </span><span class="style28">*</span><br /> <label> <select name="ProjectLength" size="1" class="style23" id="ProjectLength"> <option value="Within One Week" selected="selected">Within One Week</option> <option value="One - Two Weeks">One - Two Weeks</option> <option value="Two - Three Weeks">Two - Three Weeks</option> <option value="Three Weeks - Month">Three Weeks - Month</option> <option value="A Month - Two Months">A Month - Two Months</option> <option value="No Time Limit">No Time Limit</option> </select> </label></p></td> <td valign="top"><span class="style23">Message:<br> <textarea name="Message" cols="35" rows="6" class="style23"></textarea> </span> <p align="left" class="style23"><span class="style25"> <input name="submit" type="submit" class="style23" value="Send Message"> </span>Fields marked <span class="style26">*</span> are required.</td> </tr> </table> </form> And here is the Contact.php Code: <?php // Website Contact Form Generator // get posted data into local variables $to = "[email protected]"; $EmailFrom = Trim(stripslashes($_POST['EmailFrom'])); $EmailTo = "[email protected]"; $Subject = Trim(stripslashes($_POST['Subject'])); $Name = Trim(stripslashes($_POST['Name'])); $Website = Trim(stripslashes($_POST['Website'])); $Message = Trim(stripslashes($_POST['Message'])); $Phone = Trim(stripslashes($_POST['Phone'])); $Location = Trim(stripslashes($_POST['Location'])); $ContactMethod = Trim(stripslashes($_POST['ContactMethod'])); $Position = Trim(stripslashes($_POST['Position'])); $PriceRange = Trim(stripslashes($_POST['PriceRange'])); $ProjectLength = Trim(stripslashes($_POST['ProjectLength'])); $RequiredContent = Trim(stripslashes($_POST['RequiredContent'])); // validation $validationOK=true; if (Trim($EmailFrom)=="") $validationOK=false; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; exit; } // prepare email body text $Body = ""; $Body .= "Name: "; $Body .= $Name; $Body .= "\n"; $Body .= "Website: "; $Body .= $Website; $Body .= "\n"; $Body .= "Phone: "; $Body .= $Phone; $Body .= "\n"; $Body .= "Location: "; $Body .= $Location; $Body .= "\n"; $Body .= "Position: "; $Body .= $Position; $Body .= "\n"; $Body .= "Contact Method: "; $Body .= $ContactMethod; $Body .= "\n"; $Body .= "Price Range: "; $Body .= $PriceRange; $Body .= "\n"; $Body .= "Project Length: "; $Body .= $ProjectLength; $Body .= "\n"; $Body .= "Required Content: "; $Body .= $RequiredContent; $Body .= "\n"; $Body .= "Message: "; $Body .= $Message; $Body .= "\n"; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=ok.htm\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; } ?> If anybody could help me to get the Checkbox options sent on 1 line in the Email body ($RequiredContent) section, i'd appreciate it! Thanks! Link to comment https://forums.phpfreaks.com/topic/191463-contact-form-wcheckboxes-to-e-mail-help/ Share on other sites More sharing options...
DLR Posted February 9, 2010 Share Posted February 9, 2010 Hi, I'm not an expert, so hope this helps I see that you are using a variable name RequiredContent[] in the middle of your HTML. If " RequiredContent[]" is to be elements of an array, then I would assume you would need to switch into <?php echo $RequiredContent[]; ?> to make the variable work - else you would be overwriting the name/value pair and you would only get the last name/value pair posted. Link to comment https://forums.phpfreaks.com/topic/191463-contact-form-wcheckboxes-to-e-mail-help/#findComment-1009290 Share on other sites More sharing options...
jl5501 Posted February 9, 2010 Share Posted February 9, 2010 Your values for RequiredContent will be recieved as an array, and will need to be converted for a string to include in the email. $RequiredContent = implode(",",$_POST['RequiredContent']); Link to comment https://forums.phpfreaks.com/topic/191463-contact-form-wcheckboxes-to-e-mail-help/#findComment-1009293 Share on other sites More sharing options...
prasanthmj Posted February 9, 2010 Share Posted February 9, 2010 Since the check box group is an array, you have to iterate through the array to get the selections. Example: $RequiredContent_arr = $_POST['RequiredContent']; $RequiredContent_str=''; if(!empty($aDoor)) { $N = count($RequiredContent_arr); for($i=0; $i < $N; $i++) { $RequiredContent_str=. $RequiredContent_arr[$i].","; } } For more details on check box handling, see: Handling checkbox in a PHP form processor Link to comment https://forums.phpfreaks.com/topic/191463-contact-form-wcheckboxes-to-e-mail-help/#findComment-1009447 Share on other sites More sharing options...
jl5501 Posted February 9, 2010 Share Posted February 9, 2010 prasanthmj, does your code do anything that implode() does not do? Link to comment https://forums.phpfreaks.com/topic/191463-contact-form-wcheckboxes-to-e-mail-help/#findComment-1009455 Share on other sites More sharing options...
monstro Posted February 9, 2010 Author Share Posted February 9, 2010 The form automatically generated it to be an Array. Can I remove this? Or where do I put that code exactly? In the .php file or .html file? Where should I paste it? Link to comment https://forums.phpfreaks.com/topic/191463-contact-form-wcheckboxes-to-e-mail-help/#findComment-1009709 Share on other sites More sharing options...
monstro Posted February 9, 2010 Author Share Posted February 9, 2010 Your values for RequiredContent will be recieved as an array, and will need to be converted for a string to include in the email. $RequiredContent = implode(",",$_POST['RequiredContent']); Your solution worked! I just changed the string in the "Contact.php" page that read: $RequiredContent = Trim(stripslashes($_POST['RequiredContent'])); to this: $RequiredContent = implode(", ",$_POST['RequiredContent']); Thanks a lot! Link to comment https://forums.phpfreaks.com/topic/191463-contact-form-wcheckboxes-to-e-mail-help/#findComment-1009713 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.