Silas Posted October 14, 2011 Share Posted October 14, 2011 I am new to PHP and learning as I go I am stuck with a piece of code that I am trying to change. I have a php application that has tickboxes in and some are checked as standard. I want to change the tick box setting to be unchecked as standard. Here is the code. <label><input type="checkbox" name="notify" value="1" <?php echo (!isset($_SESSION['as_notify']) || !empty($_SESSION['as_notify'])) ? 'checked="checked"' : ''; ?> /> <?php echo $hesklang['seno']; ?></label><br /> I have tried everything I know but since I do not know that much I have been unable to change the standard. I am sure it is something small that I am overlooking. Anyone out there know what I am doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/249103-php-code-to-change-automatically-checked-check-boxes/ Share on other sites More sharing options...
AyKay47 Posted October 14, 2011 Share Posted October 14, 2011 well it looks to me like your ternary condition is a bit off.. it checks for a session not being set OR the session being set at the same time.. so one way or the other the condition will always return true.. thus resulting in your checkbox always being check.. change the ternary condition to this.. <label><input type="checkbox" name="notify" value="1" <?php echo (!empty($_SESSION['as_notify'])) ? 'checked="checked"' : ''; ?> /> <?php echo $hesklang['seno']; ?></label><br /> Quote Link to comment https://forums.phpfreaks.com/topic/249103-php-code-to-change-automatically-checked-check-boxes/#findComment-1279299 Share on other sites More sharing options...
Silas Posted October 18, 2011 Author Share Posted October 18, 2011 Thanks for the help! That sorted it for me! Quote Link to comment https://forums.phpfreaks.com/topic/249103-php-code-to-change-automatically-checked-check-boxes/#findComment-1280143 Share on other sites More sharing options...
AyKay47 Posted October 18, 2011 Share Posted October 18, 2011 no problem, please mark as solved.. Quote Link to comment https://forums.phpfreaks.com/topic/249103-php-code-to-change-automatically-checked-check-boxes/#findComment-1280154 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.