OK, so I started PHP today and I'm having a bit of a problem with checkboxes....
As with the new default settings for PHP register_globals is off, now an easy work-around would be to just edit the ini and turn it on and all these problems would disappear. However come the time I put this on a server I may not get that luxury so hence this quandry:
I have a simple form with a checkbox in - nothing elaborate just a simple test file. It calls to my PHP page and it parses it fine as long as the box is checked - Not a surprise really. So I took a sniff around the boards and found a similar problem and the solution as I had summised was to use an IF ELSE to branch the response - I still can't get this to work if the check box is empty it parses the statement block prints the value off to the screen but preceedes it with:
Notice: Undefined index: choice in checkBox.php on line 9 (Which is where the if statement block starts)
Code for HTML form is:
<html>
<head>
</head>
<body>
<form name="myform" method="post" action="checkBox.php">
Just click the box stoopid :P:
<input type="checkbox" name="choice">
<br>
<input type="submit">
</form>
<br>
</body>
</html>
PHP code in the checkBox page is:
<?php
if ($_POST['choice'] == "on"){
echo $_POST['choice'];
} else {
echo 'off';
}
?>
I know this is a bit simple but syntactically it looks correct to me and I just need some clarification
TIA
HD