grk101 Posted October 7, 2008 Share Posted October 7, 2008 hi guys,, i have searched for help but i am getting more lost with the array's etc so i decided to make a post. this is my script below, the problem is i can't get the checkboxes to send the info that is selected So if all of them are select they all send, if one selected one sends and so on.. i tried to make it an array by putting name="roominformation[]" but the word array would only send. thanks so much for any help <? $to = "blah@blah.com"; if (!isset($_POST['Submit'])) { showForm(); } else { //form submitted $error = 0; if(!preg_match("/^(?:[\w\d]+\.?)+@(??:[\w\d]\-?)+\.)+\w{2,4}$/", $_POST['email'])) { $error = 1; $errstr[] = "Please enter a valid email address"; } // if(empty($_POST['message']) || preg_match("/^enter your message here$/i", $_POST['message'])) { // $error = 1; // $errstr[] = "Please enter a message"; // } if(empty($_POST['imagetext'])) { $error = 1; $errstr[] = "Please validate the image code"; } else { include "securimage.php"; $img = new Securimage(); $valid = $img->check($_POST['imagetext']); if(!$valid) { $error = 1; $errstr[] = "The code you entered was incorrect"; } } if ($error == 1) { echo "<center>\n<font style=\"color: #FF0000\">\n"; foreach($errstr as $err) { echo "<li> " . $err . "</li>\n"; } echo "</font>\n</center>\n<br />\n\n"; showForm(); } else { @mail($to, "Room info - " . $_POST['firstname'], "\n\n Room Information:\n" . $_POST['roominformation'] . "\n\n" . stripslashes($_POST['']), "From: " . $_POST['email']); echo "<center><font color=black>\nThanks for contacting us. </font> <br /><br />" ."<font color=black>Click <a href=\"#\" onclick=\"self.close()\">here</a> to close this window.</font>"; } } //else submitted function showForm() { echo <<<EOD <div id="form"> <form method="POST"> <table border="0" class="showin"> <tr> <td>Living Room <input name="roominformation" type="checkbox" value="Living Room"/></td> <td>Dining Room <input name="roominformation" type="checkbox" value="Dining Room"/></td> <td>Great Room <input name="roominformation" type="checkbox" value="Great Room"/></td> <td>Family Room <input name="roominformation" type="checkbox" value="Family Room"/></td> <td>Den <input name="roominformation" type="checkbox" value="Den"/></td> <td>Library <input name="roominformation" type="checkbox" value="Library"/></td> <td>Laundry <input name="roominformation" type="checkbox" value="Laundry"/></td> </tr> </table> </form> </div> EOD; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/127339-checkboxes-and-email-form-php-ugh/ Share on other sites More sharing options...
Brandon Jaeger Posted October 7, 2008 Share Posted October 7, 2008 Rename the checkbox's names to roominformation[] and do this: $cb_values = $_POST["roominformation"]; foreach($cb_values as $val) { echo $val . '<br \>'; } Quote Link to comment https://forums.phpfreaks.com/topic/127339-checkboxes-and-email-form-php-ugh/#findComment-658754 Share on other sites More sharing options...
grk101 Posted October 7, 2008 Author Share Posted October 7, 2008 okay this is going to sound very stupid.. but where do i put that on my form ..... will that line pass my form? or do i still have to have the value @mail($to, "Room info - " . $_POST['firstname'], "\n\n Room Information:\n" . $_POST['roominformation'] . "\n\n" . stripslashes($_POST['']), "From: " . $_POST['email']); Quote Link to comment https://forums.phpfreaks.com/topic/127339-checkboxes-and-email-form-php-ugh/#findComment-658756 Share on other sites More sharing options...
Brandon Jaeger Posted October 7, 2008 Share Posted October 7, 2008 Put it where you're checking for errors. Something like should work: $cb_values = $_POST["roominformation"]; $cb_num = count($cb_values); // this variable will hold the # of checkboxes that are checked $total_boxes = 7; // this variable will hold the # of total checkboxes if($cb_num < $total_boxes) // if the # of checked boxes is less than the total amount of checkboxes { $error = 1; $errorstr[] = "zomg"; } Then add it all together in a string and stick it in the mail() function or however you want to do it. Quote Link to comment https://forums.phpfreaks.com/topic/127339-checkboxes-and-email-form-php-ugh/#findComment-658765 Share on other sites More sharing options...
grk101 Posted October 7, 2008 Author Share Posted October 7, 2008 I just tried this in the script passes on variable of the 7 that is selected. I tried to select four only passed one. didn't think checkboxes such more work . Quote Link to comment https://forums.phpfreaks.com/topic/127339-checkboxes-and-email-form-php-ugh/#findComment-659031 Share on other sites More sharing options...
Brandon Jaeger Posted October 7, 2008 Share Posted October 7, 2008 I'm not sure what you're trying to say. Post your most recent code, please. Quote Link to comment https://forums.phpfreaks.com/topic/127339-checkboxes-and-email-form-php-ugh/#findComment-659034 Share on other sites More sharing options...
grk101 Posted October 7, 2008 Author Share Posted October 7, 2008 This is how i put it, knowning me right now i propbably did something wrong. sorry for my bad grammar above, <? $to = "blah@blah.com"; if (!isset($_POST['Submit'])) { showForm(); } else { //form submitted $error = 0; if(!preg_match("/^(?:[\w\d]+\.?)+@(??:[\w\d]\-?)+\.)+\w{2,4}$/", $_POST['email'])) { $error = 1; $errstr[] = "Please enter a valid email address"; } // if(empty($_POST['message']) || preg_match("/^enter your message here$/i", $_POST['message'])) { // $error = 1; // $errstr[] = "Please enter a message"; // } if(empty($_POST['imagetext'])) { $error = 1; $errstr[] = "Please validate the image code"; } else { include "securimage.php"; $img = new Securimage(); $valid = $img->check($_POST['imagetext']); if(!$valid) { $error = 1; $errstr[] = "The code you entered was incorrect"; } } if ($error == 1) { echo "<center>\n<font style=\"color: #FF0000\">\n"; foreach($errstr as $err) { echo "<li> " . $err . "</li>\n"; } echo "</font>\n</center>\n<br />\n\n"; $cb_values = $_POST["roominformation"]; $cb_num = count($cb_values); // this variable will hold the # of checkboxes that are checked $total_boxes = 7; // this variable will hold the # of total checkboxes if($cb_num < $total_boxes) // if the # of checked boxes is less than the total amount of checkboxes { $error = 1; $errorstr[] = "zomg"; } showForm(); } else { @mail($to, "Room info - " . $_POST['firstname'], "\n\n Room Information:\n" . $_POST['roominformation'] . "\n\n" . stripslashes($_POST['']), "From: " . $_POST['email']); echo "<center><font color=black>\nThanks for contacting us. </font> <br /><br />" ."<font color=black>Click <a href=\"#\" onclick=\"self.close()\">here</a> to close this window.</font>"; } } //else submitted function showForm() { echo <<<EOD <div id="form"> <form method="POST"> <table border="0" class="showin"> <tr> <td>Living Room <input name="roominformation" type="checkbox" value="Living Room"/></td> <td>Dining Room <input name="roominformation" type="checkbox" value="Dining Room"/></td> <td>Great Room <input name="roominformation" type="checkbox" value="Great Room"/></td> <td>Family Room <input name="roominformation" type="checkbox" value="Family Room"/></td> <td>Den <input name="roominformation" type="checkbox" value="Den"/></td> <td>Library <input name="roominformation" type="checkbox" value="Library"/></td> <td>Laundry <input name="roominformation" type="checkbox" value="Laundry"/></td> </tr> </table> </form> </div> EOD; } Quote Link to comment https://forums.phpfreaks.com/topic/127339-checkboxes-and-email-form-php-ugh/#findComment-659042 Share on other sites More sharing options...
grk101 Posted October 8, 2008 Author Share Posted October 8, 2008 freeking checkboxes i am gonna give up and use the long method of naming each checkbox i think Quote Link to comment https://forums.phpfreaks.com/topic/127339-checkboxes-and-email-form-php-ugh/#findComment-659514 Share on other sites More sharing options...
redarrow Posted October 8, 2008 Share Posted October 8, 2008 <input name="roominformation" <input name="roominformation[]" <<<<<<<<<<<<<<<<<<<< Quote Link to comment https://forums.phpfreaks.com/topic/127339-checkboxes-and-email-form-php-ugh/#findComment-659570 Share on other sites More sharing options...
grk101 Posted October 8, 2008 Author Share Posted October 8, 2008 yeh i did that i get a reply that says " array " Quote Link to comment https://forums.phpfreaks.com/topic/127339-checkboxes-and-email-form-php-ugh/#findComment-659612 Share on other sites More sharing options...
grk101 Posted October 9, 2008 Author Share Posted October 9, 2008 well i got this.. below.. the problem is.. if no checkbox is selected, i get a forech error. not sure what to do $message .= "\n\n Room information:\n"; // put the contents of each index of roominformation into room_info foreach($_POST['roominformation'] as $room_info) { $message .= "$room_info\n"; } Quote Link to comment https://forums.phpfreaks.com/topic/127339-checkboxes-and-email-form-php-ugh/#findComment-660558 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.