tyooseph Posted June 25, 2007 Share Posted June 25, 2007 Hello, I have a form with several fields that are required if the user checks a checkbox. I am validating the form and displaying errors on the screen for the user to correct; however, the checkbox does not remain checked if errors are displayed. I've tried searching the Internet for solutions and found the following, which does not work. Am I missing something? Please advise. Thank you. <input type="checkbox" name="showSummary"<?php if($showSummary == 'on'){echo " CHECKED";}?>> Summary Link to comment https://forums.phpfreaks.com/topic/57130-solved-need-checkbox-to-stay-checked-after-submitting/ Share on other sites More sharing options...
obsidian Posted June 25, 2007 Share Posted June 25, 2007 Try this: <?php echo "<input type=\"checkbox\" name=\"showSummary\" "; echo isset($_POST['showSummary']) ? 'checked="checked" ' : ''; echo "/> Summary\n"; ?> Good luck. Link to comment https://forums.phpfreaks.com/topic/57130-solved-need-checkbox-to-stay-checked-after-submitting/#findComment-282325 Share on other sites More sharing options...
tyooseph Posted June 25, 2007 Author Share Posted June 25, 2007 Thanks! that did the trick.... Link to comment https://forums.phpfreaks.com/topic/57130-solved-need-checkbox-to-stay-checked-after-submitting/#findComment-282391 Share on other sites More sharing options...
mdvignesh Posted April 4, 2012 Share Posted April 4, 2012 Good dude Link to comment https://forums.phpfreaks.com/topic/57130-solved-need-checkbox-to-stay-checked-after-submitting/#findComment-1334245 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.