denoteone Posted November 9, 2009 Share Posted November 9, 2009 if the box is not checked on submit would that post variable be "false" <input type="checkbox" name="vitamin" checked> Quote Link to comment Share on other sites More sharing options...
Bricktop Posted November 9, 2009 Share Posted November 9, 2009 Hi denoteone, Yes it would, or more precisely it would be "off". Hope this helps. Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted November 9, 2009 Share Posted November 9, 2009 i believe that it won't be sent. (IE you can check if its set via isset and that will tell you if it was sent or not) but I could be wrong. Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted November 9, 2009 Share Posted November 9, 2009 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> Quote Link to comment Share on other sites More sharing options...
simshaun Posted November 9, 2009 Share Posted November 9, 2009 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(). Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 9, 2009 Share Posted November 9, 2009 Actually, a checked checkbox will be set and it will have the value in the value="..." attribute (if present and a default value of on if is there is no value="..." attribute.) An unchecked checkbox won't be set. Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted November 9, 2009 Share Posted November 9, 2009 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. Quote Link to comment Share on other sites More sharing options...
YDevelope Posted November 9, 2009 Share Posted November 9, 2009 actually its not true or false, its set, or not set. Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted November 9, 2009 Share Posted November 9, 2009 actually its not true or false, its set, or not set. isset() Returns TRUE if var exists; FALSE otherwise. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.