Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/67540-foreach-problems/
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/67540-foreach-problems/#findComment-339164
Share on other sites

<?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.

Link to comment
https://forums.phpfreaks.com/topic/67540-foreach-problems/#findComment-339182
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.