html check box gives errors

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
davej
Forum Newbie
Posts: 4
Joined: Mon Jun 13, 2005 1:09 pm

html check box gives errors

Post 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
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post 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'];
Post Reply