Multiple Checkboxes not Appearing in Emailed Form Results

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pura_vida
Forum Newbie
Posts: 6
Joined: Mon Sep 26, 2005 11:05 am
Location: Chicago, IL

Multiple Checkboxes not Appearing in Emailed Form Results

Post by pura_vida »

My problem is that when users slect multiple checkboxes, only one of their selection ends up in the

emailed results. I need all of their selection to appear.

Here are the bare bones of my code...

My FORM code:

Code: Select all

<form action="volunteer_formInfo.php" method="post" name="volunteerform" id="volunteerform">

 <input name="availability" type="checkbox" id="availability" value="mornings">Weekday mornings
<input name="availability" type="checkbox" id="availability" value="afternoons">Weekday afternoons 
<input name="availability" type="checkbox" id="availability" value="evenings">Weekday evenings 
<input name="availability" type="checkbox" id="availability" value="weekend">Weekend only =
<input name="availability" type="checkbox" id="availability" value="unpredictable"> Unpredictable 

hours

<input type="submit" name="Submit" value="send us the info">

</form>
My EMAIL code:

Code: Select all

<?php 

$formsent = mail("name@email.com", "Volunteer Form: $name", "\r\nTimes Available: $availability\r\ 
?>
Any advice on how my code should change so that ALL checkbox selections come through?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

example:

Code: Select all

<input name="availability[]" type="checkbox" id="availability" value="mornings">
pura_vida
Forum Newbie
Posts: 6
Joined: Mon Sep 26, 2005 11:05 am
Location: Chicago, IL

Post by pura_vida »

Thanks, but that change didn't work for me.

Don't i have to change something in the EMAIL code?

Code: Select all

$availability
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

Code: Select all

$avail = '';

foreach ($availability as $val)
  $avail .= $val."\n";
then just put the $avail instead of $availability in the mail function
pura_vida
Forum Newbie
Posts: 6
Joined: Mon Sep 26, 2005 11:05 am
Location: Chicago, IL

Post by pura_vida »

so this...

Code: Select all

$avail = ''; 

foreach ($availability as $val) 
  $avail .= $val."\n";
... goes in the mail functrion or in the form?
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

Code: Select all

<form action="volunteer_formInfo.php" method="post" name="volunteerform" id="volunteerform">

<input name="availability[]" type="checkbox" id="availability" value="mornings">Weekday mornings
<input name="availability[]" type="checkbox" id="availability" value="afternoons">Weekday afternoons
<input name="availability[]" type="checkbox" id="availability" value="evenings">Weekday evenings
<input name="availability[]" type="checkbox" id="availability" value="weekend">Weekend only =
<input name="availability[]" type="checkbox" id="availability" value="unpredictable"> Unpredictable

hours

<input type="submit" name="Submit" value="send us the info">

</form>

Code: Select all

$avail = '';

foreach ($availability as $val)
  $avail .= $val."\n";

$formsent = mail("name@email.com", "Volunteer Form: $name", "\r\nTimes Available: $avail\r");
pura_vida
Forum Newbie
Posts: 6
Joined: Mon Sep 26, 2005 11:05 am
Location: Chicago, IL

Post by pura_vida »

Thanks, that works great!
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

my pleasure
pura_vida
Forum Newbie
Posts: 6
Joined: Mon Sep 26, 2005 11:05 am
Location: Chicago, IL

Post by pura_vida »

Your suggestion worked on one instance of checkboxes, but when I tried to apply it to different checkbox areas of the form it didn't work. Here is how I have it.

Code: Select all

$avail = ''; 
foreach ($availability as $val) 
$avail .= $val.", "; 
$tech = ''; foreach ($techSkills as $val) 
$tech .= $val.", "; 
$act = ''; foreach ($activities as $val) 
$act .= $val.", ";

Should I be writing it a different way?

The above code gives me the following error message:

"Warning: Invalid argument supplied for foreach() in /home/n26chi2/public_html/volunteer_formInfo2.php on line 5

Warning: Invalid argument supplied for foreach() in /home/n26chi2/public_html/volunteer_formInfo2.php on line 7

Warning: Cannot modify header information - headers already sent by (output started at /home/n26chi2/public_html/volunteer_formInfo2.php:5) in /home/n26chi2/public_html/volunteer_formInfo2.php on line 10"
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

the foreach is because the first thing is not a array. the forms should be like name="techSkills[]" and whatnot. if you still can't figure it out then post the entire html form. the header problem - use the search feature for "headers already sent" and im positive you will find atleast 1 trillian results.
Post Reply