webref.eu Posted December 15, 2008 Share Posted December 15, 2008 Hi All If I have a checkbox in a form like: <input type="checkbox" name="RememberMe" /> What is the best technique to ensure if the user checks it, this is remembered when the form is posted back on itself. Thanks for any advice. Rgds Quote Link to comment https://forums.phpfreaks.com/topic/137036-best-way-to-remember-checked-status-on-postback/ Share on other sites More sharing options...
gevans Posted December 15, 2008 Share Posted December 15, 2008 For a remember me I'd use a cookie. You can set the length of time you'd like it to remember this setting, and easily access it across your site. Quote Link to comment https://forums.phpfreaks.com/topic/137036-best-way-to-remember-checked-status-on-postback/#findComment-715717 Share on other sites More sharing options...
webref.eu Posted December 15, 2008 Author Share Posted December 15, 2008 Thanks for your reply. To clarify, I meant to remember whether that the user had decided to check the checkbox or not. i.e. if they check it and then postback the form, and the form has to be redisplayed because of an error in another field, the form should redisplay with the checkbox checked. Rgds Quote Link to comment https://forums.phpfreaks.com/topic/137036-best-way-to-remember-checked-status-on-postback/#findComment-715726 Share on other sites More sharing options...
gevans Posted December 15, 2008 Share Posted December 15, 2008 I'd use a session here. As you're validating fields add the validated ones to a session that can be used and deleted when returned to the login Quote Link to comment https://forums.phpfreaks.com/topic/137036-best-way-to-remember-checked-status-on-postback/#findComment-715758 Share on other sites More sharing options...
webref.eu Posted December 15, 2008 Author Share Posted December 15, 2008 OK guys, I've come up with the solution and put together an explanatory tutorial: http://www.webref.eu/php-script-remember-checkbox-status-on-postback.php It works as I wanted, but if anyone has any comments, please post here. Rgds Quote Link to comment https://forums.phpfreaks.com/topic/137036-best-way-to-remember-checked-status-on-postback/#findComment-715839 Share on other sites More sharing options...
flyhoney Posted December 15, 2008 Share Posted December 15, 2008 <input type="checkbox" name="RememberMe" <?php ($_POST['RememberMe']) ? 'checked="checked"' : '' ?>/> Quote Link to comment https://forums.phpfreaks.com/topic/137036-best-way-to-remember-checked-status-on-postback/#findComment-715851 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.