Iluvatar+ Posted March 16, 2012 Share Posted March 16, 2012 Does anyone no a way to post a unchecked checkbox value? Link to comment https://forums.phpfreaks.com/topic/259060-post-checkbox-value/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 16, 2012 Share Posted March 16, 2012 You would need to put a hidden field in the form before the checkbox and use the same name as the checkbox - <form method='post' action=''> <input type='hidden' name='some_name' value='off'> <input type='checkbox' name='some_name'> <input type='submit'> </form> Link to comment https://forums.phpfreaks.com/topic/259060-post-checkbox-value/#findComment-1328071 Share on other sites More sharing options...
scootstah Posted March 16, 2012 Share Posted March 16, 2012 Why? A checkbox is a boolean - it's either on or it's off. Logically, then, if it is not "checked" it is safe to assume it is "unchecked". Link to comment https://forums.phpfreaks.com/topic/259060-post-checkbox-value/#findComment-1328072 Share on other sites More sharing options...
Iluvatar+ Posted March 16, 2012 Author Share Posted March 16, 2012 Yea but if it's returned false then teh value wont post and i need the 0 value in order to update a permission record in my table. Link to comment https://forums.phpfreaks.com/topic/259060-post-checkbox-value/#findComment-1328073 Share on other sites More sharing options...
scootstah Posted March 16, 2012 Share Posted March 16, 2012 So do something like $check = isset($_POST['checkbox']) ? 1 : 0; If the checkbox is checked it will be "1", if not it will be "0". Link to comment https://forums.phpfreaks.com/topic/259060-post-checkbox-value/#findComment-1328074 Share on other sites More sharing options...
Iluvatar+ Posted March 16, 2012 Author Share Posted March 16, 2012 Thank you, i used hidden text boxes and used jquery to toggle it's value on a ifChecked event in the end. Link to comment https://forums.phpfreaks.com/topic/259060-post-checkbox-value/#findComment-1328077 Share on other sites More sharing options...
scootstah Posted March 16, 2012 Share Posted March 16, 2012 What if they have Javascript disabled? Then it will always be "off". Link to comment https://forums.phpfreaks.com/topic/259060-post-checkbox-value/#findComment-1328080 Share on other sites More sharing options...
Psycho Posted March 16, 2012 Share Posted March 16, 2012 So do something like $check = isset($_POST['checkbox']) ? 1 : 0; If the checkbox is checked it will be "1", if not it will be "0". What he said. Using JavaScript is a really poor solution. There are sometimes hurdles when dealing with checkboxes - such as when you have a series of checkboxes to EDIT existing values. But, there are tried and true methods of handling those. Link to comment https://forums.phpfreaks.com/topic/259060-post-checkbox-value/#findComment-1328085 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.