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> Link to comment https://forums.phpfreaks.com/topic/180888-solved-_post-checkboxes/ 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. Link to comment https://forums.phpfreaks.com/topic/180888-solved-_post-checkboxes/#findComment-954262 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. Link to comment https://forums.phpfreaks.com/topic/180888-solved-_post-checkboxes/#findComment-954263 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> Link to comment https://forums.phpfreaks.com/topic/180888-solved-_post-checkboxes/#findComment-954283 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(). Link to comment https://forums.phpfreaks.com/topic/180888-solved-_post-checkboxes/#findComment-954290 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. Link to comment https://forums.phpfreaks.com/topic/180888-solved-_post-checkboxes/#findComment-954292 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. Link to comment https://forums.phpfreaks.com/topic/180888-solved-_post-checkboxes/#findComment-954296 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. Link to comment https://forums.phpfreaks.com/topic/180888-solved-_post-checkboxes/#findComment-954303 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. Link to comment https://forums.phpfreaks.com/topic/180888-solved-_post-checkboxes/#findComment-954309 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.