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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.