johnatcollege Posted July 31, 2008 Share Posted July 31, 2008 Basically, I really haven't a clue when it comes to php but I've managed to fudge together this mailer (from other stuff) but can't get the multiple check boxes to work. Can anyone help? Please. Here's the html page/code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>None</title> </head> <body> <div id="main"> <h1>Your constructive comments please </h1> <p>Many thanks for taking the time to read this handbook. I hope you found it informative and a useful introduction to the college and a useful reference document.</p> <p>If there is additional important information which you feel should be included within the next version of the Handbook, I would very much welcome any constructive comments you wish to make. Your input is very much appreciated.</p> <form action="mailer.php" method="post"> <p><span class="bold">Please indicate those sections you found most helpful and give details below:</span></p> 1 <input type="checkbox" name="Mosthelpfulsections[]" value="1" /> 2 <input type="checkbox" name="Most helpful sections[]" value="2" /> 3 <input type="checkbox" name="Most helpful sections[]" value="3" /> 4 <input type="checkbox" name="Most helpful sections[]" value="4" /> 5 <input type="checkbox" name="Most helpful sections[]" value="5" /> 6 <input type="checkbox" name="Most helpful sections[]" value="6" /> 7 <input type="checkbox" name="Most helpful sections[]" value="7" /> 8 <input type="checkbox" name="Most helpful sections[]" value="8" /> 9 <input type="checkbox" name="Most helpful sections[]" value="9" /> 10 <input type="checkbox" name="Most helpful sections[]" value="10" /> 11 <input type="checkbox" name="Most helpful sections[]" value="11" /> 12 <input type="checkbox" name="Most helpful sections[]" value="12" /> 13 <input type="checkbox" name="Most helpful sections[]" value="13" /> <br /> <p><span class="bold">Please indicate those sections you found least helpful and give details below:</span></p> 1 <input type="checkbox" name="Least helpful sections[]" value="1" /> 2 <input type="checkbox" name="Least helpful sections[]" value="2" /> 3 <input type="checkbox" name="Least helpful sections[]" value="3" /> 4 <input type="checkbox" name="Least helpful sections[]" value="4" /> 5 <input type="checkbox" name="Least helpful sections[]" value="5" /> 6 <input type="checkbox" name="Least helpful sections[]" value="6" /> 7 <input type="checkbox" name="Least helpful sections[]" value="7" /> 8 <input type="checkbox" name="Least helpful sections[]" value="8" /> 9 <input type="checkbox" name="Least helpful sections[]" value="9" /> 10 <input type="checkbox" name="Least helpful sections[]" value="10" /> 11 <input type="checkbox" name="Least helpful sections[]" value="11" /> 12 <input type="checkbox" name="Least helpful sections[]" value="12" /> 13 <input type="checkbox" name="Least helpful sections[]" value="13" /> <p><span class="bold">Remarks as above and any additional information you would have liked or <br /> any other improvement comments?</span> <br /> <textarea name="Comments" cols="60" rows="10"></textarea> </p> <p><span class="bold">Your Name:</span><br /> <input type="text" name="name" /> </p> <p><span class="bold">Date</span><br /> <input type= "text" name="date" /> </p> <input type="submit" value="submit"> </form> </div> </body> </html> Now here's the php. I've tried a number of things but can't seem to get the results I'm looking for. The most common thing that would happen would be that it would only display the results from one box. <?php $FIELDS = array('name', 'date', 'Comments', 'Most helpful sections', 'Least helpful sections'); $EMAILS = array('[email protected]'); $thankyouurl = "sent.html" ; if ($_SERVER['REQUEST_METHOD'] != 'POST') { die(); } $out = array(); foreach ($FIELDS as $f) { $out[$f] = $_REQUEST[$f]; } if (count($EMAILS) > 0) { $msg = ''; foreach ($out as $k => $v) { $msg .= ucfirst($k) . ":\n"; $msg .= $v . "\n\n"; } foreach ($EMAILS as $e) { mail($e, "Mail from Staff Induction Handbook", $msg, "From: Online_Staff_Induction"); } } header( "Location: $thankyouurl" ); ?> If I were to only check boxes 1 and 2 in the 'Most helpful section' this is how I'd like the e-mail to look: Name: John Maguire Date: 30 July 2008 Comments: It's rubbish Most helpful sections: 1, 2 Least helpful sections: If anyone can help I'd just like to thank you in advance. Link to comment https://forums.phpfreaks.com/topic/117551-multiple-checkboxes-i-honestly-havent-a-clue/ Share on other sites More sharing options...
discomatt Posted July 31, 2008 Share Posted July 31, 2008 Change all instances of <input type="checkbox" name="Most helpful sections[]" ... /> to <input type="checkbox" name="Mosthelpfulsections[]" ... /> Then use implode( ', ', $_POST['Mosthelpfulsections'] ); to convert the array of selected values to a comma separated string Link to comment https://forums.phpfreaks.com/topic/117551-multiple-checkboxes-i-honestly-havent-a-clue/#findComment-604593 Share on other sites More sharing options...
johnatcollege Posted July 31, 2008 Author Share Posted July 31, 2008 I'm really not familliar with php but I tried what you suggested and in resulting e-mail it now says Array where the numbers should be. Maybe I'm not putting the implode line in the right place? ??? The php I've got was taken from a mates project but he got someone else to do that and hasn't a clue how to sort this. Link to comment https://forums.phpfreaks.com/topic/117551-multiple-checkboxes-i-honestly-havent-a-clue/#findComment-604618 Share on other sites More sharing options...
discomatt Posted July 31, 2008 Share Posted July 31, 2008 Only because I'm in a good mood Change foreach ($out as $k => $v) { $msg .= ucfirst($k) . ":\n"; $msg .= $v . "\n\n"; } to foreach ($out as $k => $v) { $msg .= ucfirst($k) . ":\n"; if ( is_array($v) ) $msg .= implode( ', ', $v ) . "\n\n"; else $msg .= $v . "\n\n"; } Give that a shot Link to comment https://forums.phpfreaks.com/topic/117551-multiple-checkboxes-i-honestly-havent-a-clue/#findComment-604646 Share on other sites More sharing options...
johnatcollege Posted August 1, 2008 Author Share Posted August 1, 2008 I really can't thank you enough, worked a treat. I'd never have figured this out. Thanks again. Link to comment https://forums.phpfreaks.com/topic/117551-multiple-checkboxes-i-honestly-havent-a-clue/#findComment-605383 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.