Forum Moderators: coopster

Message Too Old, No Replies

Trouble with Checkboxes

Trouble with having checkboxes returning multiple values in email

         

DeighMann

9:32 pm on Jan 24, 2006 (gmt 0)

10+ Year Member



I am new to php as you will soon see. I have a simple form with some checkboxes. I have the results of the form sent to an email address. For what ever reason the checkboxes only show array if more than one is checked. What am I doing wrong?

Here's the code handling the checkboxes.

<input name="dayToDay[]" type="checkbox" id="dayToDay" value="phonecalls">
Making/receiving phone calls</label>
<br>
<label>
<input name="dayToDay[]" type="checkbox" id="dayToDay" value="envelopes">
Stuffing envelopes</label>
<br>
<label>
<input name="dayToDay[]" type="checkbox" id="dayToDay" value="filing">
Filing</label>
<br>
<label>
<input name="dayToDay[]" type="checkbox" id="dayToDay" value="copies">
Making Copies</label>
<br>
<label>
<input name="dayToDay[]" type="checkbox" id="dayToDay" value="typing">
Typing</label>
<br>
<label>
<input name="dayToDay[]" type="checkbox" id="dayToDay" value="activities">
Assisting with group activities</label>
<br>
<label>
<input name="dayToDay[]" type="checkbox" id="dayToDay" value="other">
Other</label>
<input name="otherTF" type="text" id="otherTF" size="20" maxlength="50">
</span> <label></label>

Heres the other part.

<?php
@extract($_POST);
$firstName = stripslashes($firstName);
$lastName = stripslashes($lastName);
$address = stripslashes($address);
$city = stripslashes($city);
$state = stripslashes($state);
$zipCode = stripslashes($zipCode);
$phone = stripslashes($phone);
$email = stripslashes($email);
$faxNo = stripslashes($faxNo);
$dayToDay = stripslashes($dayToDay);
$otherTF = stripslashes($otherTF);
$specialEvent = stripslashes($specialEvent);
$days = stripslashes($days);
$am = stripslashes($am);
$pm = stripslashes($pm);
$spEvAM = stripslashes($spEvAM);
$spEvPM = stripslashes($spEvPM);
mail('#*$!@xxxx.com','Volunteer Form', "From: $lastName, $firstName <$email>
First Name: $firstName
Last Name: $lastName
Address: $address
City: $city
State: $state
Zip Code: $zipCode
Phone: $phone
Email: $email
Fax: $faxNo
Availability for Day to day operation: $dayToDay
Other: $otherTF
Availability for Special Events: $specialEvent
Days: $days
AM: $am
PM: $pm
Special Event AM: $spEvAM
Special Event PM: $spEvPM");

?>

inveni0

12:07 am on Jan 25, 2006 (gmt 0)

10+ Year Member



You need a foreach statement to grab the array and split it into different variables. I'm not sure of the syntax, but I had the same problem once.

It's something like:

foreach ($_POST('dayToDay') AS $Key => $dayToDay) {

blah blah blah here;

}

It's something like that...I'm sure someone will come along and correct me. I'm new, too.

DrDoc

6:25 am on Jan 25, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld! [WebmasterWorld.com]

inveni0 is correct (except that the variable reference should have square braces: $_POST['dayToDay'])

Another thing you can do is replace the line:

$dayToDay = stripslashes($dayToDay);

with:
$dayToDay = stripslashes([url=http://www.php.net/implode]implode[/url](", ", $dayToDay));

DeighMann

10:49 pm on Jan 25, 2006 (gmt 0)

10+ Year Member



Thanx guys for your help. It works like a charm.