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>

Link to comment
Share on other sites

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().

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.