Snugg Posted September 1, 2007 Share Posted September 1, 2007 okay, first thing to know is that this is an event sign-up sheet, so it has a few text fields (which work fine) and three text boxes (which are my problem). when the person hits submit on the form, it needs to send an email to my email address that has all of the information in it and ONLY the checked check boxes. My problem is that with using foreach, the email only tells me the last text box of the three they checked. (if they checked boxes 1 and 2, only 2 will be listed, as well as if they checked all three boxes, only the third will be listed..) here is the code for the form submission.. [code=php:0]<?php if (getenv(HTTP_X_FORWARDED_FOR)) { $ip = getenv(HTTP_X_FORWARDED_FOR); } else { $ip = getenv(REMOTE_ADDR); } $adminEmail = "admin@berryrotc.com"; $subject = "Event Participation"; $Name = $_POST['Name']; $Rank = $_POST['Rank']; $LetLevel = $_POST['LetLevel']; $ClassPeriod = $_POST['ClassPeriod']; $Comments = $_POST['Comments']; $Event = $_POST['Event']; foreach ($Event as $Eventname) $finalMessage = "$Rank $Name would like to participate in an upcoming event. More information below.\n\nRank: $Rank \nName: $Name \nLet Level: $LetLevel \nClass Period: $ClassPeriod \nEvents to participate in: \n $Eventname \n\n\nComments:\n$Comments"; $str = "Rank: $Rank \nName: $Name \nLetLevel: $LetLevel \nClass Period: $ClassPeriod \n$Eventname \n\n\nComments: \n$Comments"; $out = fopen("backup_contact_form.txt", "a+"); mail($adminEmail, $subject, $finalMessage); fwrite($out, $str); fclose($out); echo "<font color=\"white\">Thank you for signing up for JROTC Events. Your name will be added to the roster shortly!</font>"; ?> [/code] See anything that might be wrong? thanks in advance for any ideas or help offered. Quote Link to comment https://forums.phpfreaks.com/topic/67540-foreach-problems/ Share on other sites More sharing options...
marcus Posted September 1, 2007 Share Posted September 1, 2007 Well duh, make sure you're passing the field as an array. <input type="checkbox" name="sexy[]" id="1-3"> Quote Link to comment https://forums.phpfreaks.com/topic/67540-foreach-problems/#findComment-339160 Share on other sites More sharing options...
marcus Posted September 1, 2007 Share Posted September 1, 2007 Also, when you're defining the values in the foreach statement give them names that have a line break or something, so they don't get all cluttered. Quote Link to comment https://forums.phpfreaks.com/topic/67540-foreach-problems/#findComment-339161 Share on other sites More sharing options...
Snugg Posted September 1, 2007 Author Share Posted September 1, 2007 i did both, and still no success. here is the code for the checkboxes.. <input type="checkbox" name="Event[]<br>" id="1-3" value="Softball" style="font-weight: 700" size="20"><b><font size="2">Softball</font></b> <input type="checkbox" name="Event[]<br>" id="2-3" value="Field Day" style="font-weight: 700" size="20"><b><font size="2">Field Day</font></b> <input type="checkbox" name="Event[]<br>" id="3-3" value="Ft. Fisher" style="font-weight: 700" size="20"><b><font size="2">Ft. Fisher</font></b> Quote Link to comment https://forums.phpfreaks.com/topic/67540-foreach-problems/#findComment-339164 Share on other sites More sharing options...
darkfreaks Posted September 1, 2007 Share Posted September 1, 2007 <?php while (list ($key,$val) = @each ($box)) { echo "$val,"; } ?> <input type=checkbox name=box[] value='Mathew'> Quote Link to comment https://forums.phpfreaks.com/topic/67540-foreach-problems/#findComment-339167 Share on other sites More sharing options...
Snugg Posted September 1, 2007 Author Share Posted September 1, 2007 erm.. what do i do with that? sorry, im quite new to php.. Quote Link to comment https://forums.phpfreaks.com/topic/67540-foreach-problems/#findComment-339176 Share on other sites More sharing options...
darkfreaks Posted September 1, 2007 Share Posted September 1, 2007 put the top part into your code it will make the checkboxes check Quote Link to comment https://forums.phpfreaks.com/topic/67540-foreach-problems/#findComment-339177 Share on other sites More sharing options...
Ken2k7 Posted September 1, 2007 Share Posted September 1, 2007 <?php echo " <form action='{$_SERVER['PHP_SELF']}' method='post'> <input name='softball' type='checkbox' value='softball' /> Softball<br /> <input name='field' type='checkbox' value='field' /> Field Day<br /> <input name='fisher' type='checkbox' value='fisher' /> Ft. Fisher<br /> <input name='submit' type='Submit' value='Submit'><br /> </form>"; if($_POST['submit']){ foreach ($_POST as $p) if ($p != "Submit") echo $p . "<br />"; } ?> That should print all the values out. Quote Link to comment https://forums.phpfreaks.com/topic/67540-foreach-problems/#findComment-339182 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.