gaz-boy Posted June 22, 2010 Share Posted June 22, 2010 Hello I am very new to php freaks but have been using it for many years to help me learn web development. I am struggling with some code that I hope you guys might be able to help me with. I want to send checkbox data from a form my email address. Form <form name="feedback-form" id="feedback-form" action="" method="post"> Name: <input name="name" type="text" size="20" maxlength="30" class="required"> Email: <input name="email" type="text" size="20" maxlength="30" class="required"> Your favorite name? <input type="checkbox" name="id[1]" value="1" /> Mike <br /> <input type="checkbox" name="id[2]" value="1" /> John <br /> <input type="checkbox" name="id[3]" value="1" /> George <br /> <input type="checkbox" name="id[4]" value="1" /> Jane <br /> <input type="checkbox" name="id[5]" value="1" /> Sarah <br /> </td></tr> <input type="Submit" value="Send Message"> </form> PHP <?php if ($_POST["email"]<>'') { $ToEmail = 'EMAILADDRESS'; $EmailSubject = 'Video Feed Back'; $mailheader = "From: ".$_POST["email"]."\r\n"; $mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; $MESSAGE_BODY = "".$_POST["name"]." posted some feedback on Light Move Image. See The feedback below.<br>"; $MESSAGE_BODY .= "<b>Name:</b> ".$_POST["name"]."<br>"; $MESSAGE_BODY .= "<b>E-mail:</b> ".$_POST["email"]."<br>"; $MESSAGE_BODY .= "<b>Favourite Name:</b> ".$_POST["id"]."<br>"; mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); ?> I have tried to change the checkbox to an array but it is still not working. Does anybody have any ideas? Link to comment https://forums.phpfreaks.com/topic/205531-form-sending-checkbox-not-working/ Share on other sites More sharing options...
bluejay002 Posted June 22, 2010 Share Posted June 22, 2010 The checkbox you created below will be treated in PHP as an array: <input type="checkbox" name="id[1]" value="1" /> Mike <br /> <input type="checkbox" name="id[2]" value="1" /> John <br /> <input type="checkbox" name="id[3]" value="1" /> George <br /> <input type="checkbox" name="id[4]" value="1" /> Jane <br /> <input type="checkbox" name="id[5]" value="1" /> Sarah <br /> And using $_POST["id"] would return an array instance and not a value so you won't get any value from it. Assign index to it or use loop to get the value from $_POST["id"] . 1. example using index: $_POST["id"][0] 2. example using a loop: foreach($_POST["id"] as $key => $value) { echo $key." -> ".$value; } There's my two cents. cheers, bluejay Link to comment https://forums.phpfreaks.com/topic/205531-form-sending-checkbox-not-working/#findComment-1075527 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.