webref.eu Posted July 31, 2008 Share Posted July 31, 2008 Hi All I have the following checkbox: <input type="checkbox" name="chkSubscribeToNewsletter" value="1" /> how do I make sure if they user has decided to check this, that this status gets remembered when I post back the form to itself and the form needs do be displayed again because other fields contain errors? Currently when this happens I am losing the check if the user put one in. Rgds Link to comment https://forums.phpfreaks.com/topic/117522-solved-remember-the-status-of-a-checkbox-on-postback/ Share on other sites More sharing options...
jesushax Posted July 31, 2008 Share Posted July 31, 2008 this will work <input type="checkbox" name="chkSubscribeToNewsletter" value="1" <?php if ($_POST["chkSubscribeToNewsletter"] == 1) {echo 'checked="checked"'."\n";} /> Link to comment https://forums.phpfreaks.com/topic/117522-solved-remember-the-status-of-a-checkbox-on-postback/#findComment-604476 Share on other sites More sharing options...
webref.eu Posted July 31, 2008 Author Share Posted July 31, 2008 Thanks, that's great. Rgds Link to comment https://forums.phpfreaks.com/topic/117522-solved-remember-the-status-of-a-checkbox-on-postback/#findComment-604492 Share on other sites More sharing options...
webref.eu Posted July 31, 2008 Author Share Posted July 31, 2008 One question though, is there any particular reason why you used a line break character at the end of your echo statement? Many thanks Link to comment https://forums.phpfreaks.com/topic/117522-solved-remember-the-status-of-a-checkbox-on-postback/#findComment-604498 Share on other sites More sharing options...
jesushax Posted July 31, 2008 Share Posted July 31, 2008 no no reason at all, just force of habit Link to comment https://forums.phpfreaks.com/topic/117522-solved-remember-the-status-of-a-checkbox-on-postback/#findComment-604503 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.