Page 1 of 1

html check box gives errors

Posted: Tue Oct 10, 2006 8:00 pm
by davej
Hi All
I have a html form with a check box the file is called form.php. The value of the check box when checked is set to true. the form is submited to handler.php. There I need to know if the check box was checked or not.

html form

Code: Select all

<form name="form1" method="post" action="tempPros.php">
<input name="checkbox" type="checkbox"  id="checkbox" value="true">
</form>
my php

Code: Select all

echo $_POST['checkbox']
ok here if it is checked that it works. but if it is not checked it returns
Notice: Undefined index: checkbox in c:\Inetpub\wwwroot\handler.php on line 16
I am lost please help how do I get my code to not break with the check box not checked?

thanx dave

Posted: Tue Oct 10, 2006 8:03 pm
by Luke
that's because if it's not checked, it doesn't exist in the results.

Code: Select all

if(isset($_POST['checkbox'])) echo $_POST['checkbox'];