Jump to content

PHP Code to change automatically checked check boxes


Silas

Recommended Posts

I am new to PHP and learning as I go  :D 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?

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 />

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.