...

View Full Version : Form not processing check boxes.



rahul8590
08-22-2009, 05:35 PM
I have created a simple html+ php form for processing the checkboxes.
If the checkbox is clicked , then i get the desired message or i get error



Notice: Undefined index: checkbox1 in C:\wamp\www\db\output.php on line 2
User denied clicking the frog.


The html code is

<html>
</body>

<form method=post action="output.php">
<label><input type="checkbox" name="checkbox1" value="helpivebeenclicked">Please click me, I look like a frog, but I'm a princess!</label>
<br>
<label><input type="checkbox" name="checkbox2" value="noclicked">I am not going to click on it </label>
<br>
<input type=submit>
</form>

</body>
</html>



the php code is :



<?php
$checkbox1=$_REQUEST["checkbox1"];
$checkbox2=$_REQUEST["checkbox2"];
if($checkbox1=="helpivebeenclicked"){echo "User released the princess!";}
if($checkbox2=="noclicked") {echo "User denied clicking the frog.";}

?>



if both the boxes are clicked then there isnt ne problem . But if they are unclicked then i get these creepy errors.

kbluhm
08-22-2009, 07:06 PM
Unchecked checkboxes are not included with the form submission. Check for their existence with isset().

barkermn01
08-22-2009, 07:15 PM
<?php
$checkbox1= (isset($_POST["checkbox1"]))? $_POST["checkbox1"]:"";
$checkbox2= (isset($_POST["checkbox2"]))? $_POST["checkbox2"]:"";
if($checkbox1=="helpivebeenclicked"){echo "User released the princess!";}
if($checkbox2=="noclicked") {echo "User denied clicking the frog.";}

?>

rahul8590
08-22-2009, 08:50 PM
Thanks , it worked wonderfully.
But now if i want to generate those check boxes dynamically , then how do i proceed ?

I mean , there is a text box and the end user will put in some number to it .
The check boxes (2 of them which i created ) must be generated in accordingly.

Example :

how many participants : 3


checkbox1
checkbox2

checkbox1
checkbox2

checkbox1
checkbox2

Is there any way i can do that ?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum