HELP!!! PLEASE! PHP ARRAY OF CHECKED BOXES

I am having trouble with the final output of my online order form. On the html form, I have many check boxes. When the form goes through php document, it sends a line with ALL of the available options and a YES for the one the person has checked. How do I receive ONLY the items a person has checked. Do I create an array? And if so, how do I do so?
Here is the php script :

<?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = '[email protected]'; $emailSubject = ' ORDER FORM'; $webMaster = '[email protected]'; $yourFeedbackmail = '[email protected]'; } // This is to collect box array value as global_variables is set off in PHP5 by default $box=$_POST['box']; while (list ($key,$val) = @each ($box)) { echo "$val,"; } echo ""; // validation expected data exists if(!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['telephone']) || !isset($_POST['email']) || !isset($_POST['comments'])) { die('We are sorry, but there appears to be a problem with the form your submitted.'); } $first_name = $_POST['first_name']; // required $last_name = $_POST['last_name']; // required $address = $_POST['address']; // not required $cross_roads = $_POST['cross_roads']; // not required $city = $_POST['city']; // not required $state = $_POST['state']; // not required $zip = $_POST['zip']; // not required $email = $_POST['email']; // not required $telephone = $_POST['telephone']; // required $cell_phone = $_POST['cell_phone']; // not required $party_date = $_POST['party_date']; // not required $how_did_you_hear = $_POST['how_did_you_hear']; // not required $comments = $_POST['comments']; // not required $NemoWhoaDudeBouncer = $_POST['NemoWhoaDudeBouncer']; //not required $DisneyPrincess =$_POST['DisneyPrincess']; //not required $IRON_MAN =$_POST['IRON_MAN']; //not required $GreenDino =$_POST['GreenDino']; //not required $BellyClown =$_POST['BellyClown']; //not required $MedievalCastle =$_POST['MedievalCastle']; //not required $DollHOUSE15X15 =$_POST['DollHOUSE15X15']; //not required $RoyalCastle =$_POST['RoyalCastle']; //not required $MonsterTruck =$_POST['MonsterTruck']; //not required $ScoobyDoo =$_POST['ScoobyDoo']; //not required $DollHouse13X13 =$_POST['DollHouse13X13']; //not required $SpongeBob =$_POST['SpongeBob']; //not required $SpidermanYELLOW =$_POST['SpidermanYELLOW']; //not required $Spiderman =$_POST['Spiderman']; //not required $GreenBeast =$_POST['GreenBeast']; //not required $Spidey =$_POST['Spidey']; //not required $Baseball =$_POST['Baseball']; //not required $Football =$_POST['Football']; //not required $Halloween =$_POST['Halloween']; //not required $Christmas =$_POST['Christmas']; //not required $ComboCastle =$_POST['ComboCastle']; //not required $ComboSpongebob =$_POST['ComboSpongebob']; //not required $SportsREFEREE =$_POST['SportsREFEREE']; //not required $SportsClub =$_POST['SportsClub']; //not required $QueenCastle =$_POST['QueenCastle']; //not required $KnightCastle =$_POST['KnightCastle']; //not required $Disney3D5in1 =$_POST['Disney3D5in1']; //not required $FOURInOne =$_POST['FOURInOne']; //not required $FIVEInOne =$_POST['FIVEInOne']; //not required $CHUGGYONLY =$_POST['CHUGGYONLY']; //not required $body = <<<EOD


SELECTED: $val
Email: $email
First Name: $first_name
Last Name: $last_name
Address: $address
Cross Roads: $cross_roads
City: $city
State: $state
Zip Code : $zip Email: $email Telephone: $telephone
Cell Phone: $cell_phone
Party Date: $party_date
How Did You Hear About Fun N Jump?: $how_did_you_hear

Comments: $comments



NEMO BOUNCER: $NemoWhoaDudeBouncer
DISNEY PRINCESS: $DisneyPrincess
IRON MAN: $IRON_MAN
GREEN DINO: $GreenDino
BELLY CLOWN: $BellyClown
MedievalCastle: $MedievalCastle
DollHOUSE15X15: $DollHOUSE15X15
RoyalCastle: $RoyalCastle
MonsterTruck: $MonsterTruck
ScoobyDoo: $ScoobyDoo
DollHouse13X13: $DollHouse13X13
SpongeBob: $SpongeBob
SpidermanYELLOW: $SpidermanYELLOW
Spiderman: $Spiderman
GreenBeast: $GreenBeast
Baseball: $Baseball
Football: $Football
Halloween: $Halloween
Christmas: $Christmas
ComboCastle: $ComboCastle
ComboSpongebob: $ComboSpongebob
SportsREFEREE: $SportsREFEREE
SportsClub: $SportsClub
QueenCastle: $QueenCastle
KnightCastle: $KnightCastle
Disney3D5in1: $Disney3D5in1
FOURInOne: $FOURInOne
FIVEInOne: $FIVEInOne
CHUGGYONLY: $CHUGGYONLY
EOD; $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "First Name: ".clean_string($first_name)."\n"; $email_message .= "Last Name: ".clean_string($last_name)."\n"; $email_message .= "Email: ".clean_string($email)."\n"; $email_message .= "Telephone: ".clean_string($telephone)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email."\r\n". $headers .="Content-type: text/html\r\n"; $success = mail ($webMaster, $emailSubject, $body, $headers); /* Results rendered as HTML */

Hi there,

If I understand correctly, setting the name attributes of your checkboxes to name=“check[insert variable id]” will create an array ($_POST[‘check’]) of the checkboxes. For me, the array only contains the checked boxes - leaving you with the array $_POST[‘check’] which contains [random/checkbox specific id] => on for each box.

e.g.

<?php
echo "<pre>";
print_r("\$_POST ");
print_r($_POST);
echo "</pre>";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title></title>
    </head>
    <body>
		<form action="" method="post">
			<input type="checkbox" name="check['check1']" value="1" />
			<input type="checkbox" name="check['check2']" value="1" />
			<input type="checkbox" name="check['check3']" value="1" />
			<input type="checkbox" name="check['check4']" value="1" />
			<input type="submit" value="Submit" />
		</form>
    </body>
</html>

Just a quick form I made, hope this helps? Let me know if I misunderstood the problem.

Sponsor our Newsletter | Privacy Policy | Terms of Service