Page 1 of 1

Multiple Checkboxes not Appearing in Emailed Form Results

Posted: Mon Sep 26, 2005 11:40 am
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?

Posted: Mon Sep 26, 2005 11:43 am
by feyd
example:

Code: Select all

<input name="availability[]" type="checkbox" id="availability" value="mornings">

Posted: Mon Sep 26, 2005 11:51 am
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

Posted: Mon Sep 26, 2005 12:19 pm
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

Posted: Mon Sep 26, 2005 12:24 pm
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?

Posted: Mon Sep 26, 2005 12:27 pm
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");

Posted: Mon Sep 26, 2005 12:42 pm
by pura_vida
Thanks, that works great!

Posted: Mon Sep 26, 2005 12:49 pm
by shiznatix
my pleasure

Posted: Mon Sep 26, 2005 1:05 pm
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"

Posted: Mon Sep 26, 2005 1:09 pm
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.