Jump to content

[SOLVED] $_POST checkboxes


denoteone

Recommended Posts

a checkbox will return true/false:

 

<?php
echo (isset ($_POST['checkbox']) ? 'checkbox has been set (true)' : 'checkbox not set (false)');
?>
<form action="" method="post">
<input type="checkbox" name="checkbox" value="" /> <input type="submit" name="submit" />
</form>

The answer has been presented, but I would like to elaborate on mrMarcus's post.

 

Not "checking" a checkbox will not cause it to have a value of FALSE in the $_POST array.  It simply will not exist (which is what mrMarcus was implying in his code), which is why you must use isset().

based off of the OP's code, a checkbox without a value will return true ("set") if the checkbox has been checked in the form .. otherwise, under the same conditions, it will return false ("unset").

 

if the OP wanted to talk value's, all he/she had to do is ask .. but, from my experience around here, it's best to not over-think a question, since there is a chance the original question hasn't much thought in it to begin with.

 

i was simply demonstrating a quick way to determine the presence of a submitted, or non-submitted checkbox using isset();

 

that is all.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.