Reputation: 237
I have a html form
<form action="process.php" method="post">
<input type="checkbox" name="name[v1]" />
<input type="checkbox" name="name[v2]" />
<input type="checkbox" name="name[v3]" />
<input type="submit" name="update" value="update">
</form>
If they is only one check box is ticked then I only see that check box
Array ( [\'v3\'] => on )
If I have checked all three box then I see them all.
Array
(
[\'v1\'] => on
[\'v2\'] => on
[\'v3\'] => on
)
Is they any way I can see all of my checkbox even if they are not checked.
process.php
foreach( $_POST['name'] as $k => $v )
{
echo "key: ".$k;
}
Upvotes: 1
Views: 88
Reputation: 12244
Checkboxes and radio buttons are not passed on to the processing script if they don't have a "checked" attribute set. This is HTML4 by design.
The only way you can set a state is using something like:
if(!isset($_POST['mycheckbox'])){ $_POST['mycheckbox'] = 0; }
or better yet:
$_POST['mycheckbox'] = isset($_POST['checkbox']);
Regarding radio buttons, you should only use the first version since radio buttons can have more than one value so instead of setting a TRUE/FALSE in them, you want to set a default value instead.
Another note, DISABLED elements are not posted, even if they have a value, you will never see them, this is another design feature of HTML4+
Upvotes: 2