goa103,
I don't think your post is entirely accurate. An unchecked checkbox does not post at all. It's simply skipped and it does not get a value of 0. A posted checkbox will have either a value of 'on' or whatever the value attribute has.
<form method="post" action="test.php">
<input type="checkbox" name="box">Check Me</input><br />
<input type="checkbox" name="boxes[]" value="24">Check Me</input><br />
<input type="checkbox" name="boxes[]" value="42">Check Me</input><br />
<input type="submit" name="submit" value="Submit">
</form>
<?php
error_reporting(E_ALL);
if (isset($_POST['submit']))
{
if (isset($_POST['box']))
{
echo 'BOX ' . $_POST['box'] . '<br />';
}
else echo 'BOX NOT SET <br />';
if (isset($_POST['boxes']))
{
$boxes = $_POST['boxes'];
foreach ($boxes as $box)
{
echo 'BOXES ' . $box . '<br />';
}
}
else echo 'BOXES NOT SET <br />';
}
?>
Try submiting with and without the 'box' element being checked. See the difference?
Where it becomes more challenging is when you have an array of check boxes. Unchecked boxes don't even post so the only way of knowing which boxes were checked is being giving them a unique value.