Hi all,

Sorry about this but, I need some help ASAP. I have been working on a form all day, which I built in dreamweaver CS4. Here is where I need help, on the form have a list of options in the form of checkboxes Buttons BUT when the form is sent back onlu one of the options is listed. below is the code for a test form, and this works in the same way. What am I doing wrong.

Thaanks in advance.

John

HTML CODE----------------------

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>only one working out of list
</head>

<body>
<form id="form1" name="form1" method="post" action="test.php">
<p>
<label>
<input type="checkbox" name="test" value="Bus" id="test_0" />
Bus</label>
<br />
<label>
<input type="checkbox" name="test" value="Car" id="test_1" />
Car</label>
<br />
<label>
<input type="checkbox" name="test" value="Bike" id="test_2" />
Bike</label>
<br />
<label>
<input type="checkbox" name="test" value="Coach" id="test_3" />
Coach</label>
<br />
<label>
<input type="checkbox" name="test" value="Taxi" id="test_4" />
Taxi</label>
<br />
</p>
</p>
<p>&nbsp;</p>

<p>
<input type="submit" name="button" id="button" value="Submit" />
</p>
</form>
</body>
</html>


PHP CODE --------------------------------
<?php


// Receiving variables
@$pfw_ip= $_SERVER;
@$test = addslashes($_POST);

// Validation
//Sending Email to form owner
$pfw_header = "From: $test\n"
. "Reply-To: $test\n";
$pfw_subject = "test form";
$pfw_email_to = "Email address";
$pfw_message = "Visitor's IP: $pfw_ip\n"
. "vehicle: $test\n";
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

header("Location: thankyou.html");

?>

Recommended Answers

All 3 Replies

make your checkboxes an array

<input type="checkbox" name="test[]" value="Taxi" id="test_4" />

once they're stored on array you can easily traverse using foreach()

foreach($_POST['test'] as $index => $val){
echo "test[".$index."]=".$val; // just testing the value
}

Hi vaultdweller123

is there any chance, you can put some more explanation into the code. You have very kindly posted?

Kind regards John

Member Avatar for rajarajan2017

HTML CODE

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CheckBoxes</title>only one working out of list
</head>

<body>
<form id="form1" name="form1" method="post" action="test.php">
<p>
<label>
<input type="checkbox" name="test[]" value="Bus" id="test_0" />
Bus</label>
<br />
<label>
<input type="checkbox" name="test[]" value="Car" id="test_1" />
Car</label>
<br />
<label>
<input type="checkbox" name="test[]" value="Bike" id="test_2" />
Bike</label>
<br />
<label>
<input type="checkbox" name="test[]" value="Coach" id="test_3" />
Coach</label>
<br />
<label>
<input type="checkbox" name="test[]" value="Taxi" id="test_4" />
Taxi</label>
<br />
</p>
</p>
<p>&nbsp;</p>

<p>
<input type="submit" name="button" id="button" value="Submit" />
</p>
</form>
</body>
</html>

PHP CODE:

<?php
foreach($_POST['test'] as $index => $val){
echo "test[".$index."]=".$val;
}
?>

Just test it. you will catch the point!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.