4

I have a form:

<form method="post" action="">
    <p><input type="text" name="login" value="<?php if(isset($login_username)){ echo $login_username; } ?>" placeholder="<?php echo $lang['login_1']; ?>"></p>
    <p><input type="password" name="password" value="" placeholder="<?php echo $lang['login_2']; ?>"></p>

    <div class="options" style="margin: 5;line-height: 1.4;">
        <a onclick="showRegister();"><?php echo $lang['login_4']; ?></a><br>
        <a onclick="lostPassword();"><?php echo $lang['login_5']; ?></a>
    </div>

    <p class="remember_me">
        <label>
            <input type="checkbox" id="remember" <?php if(isset($login_remember)){ if($login_remember == "on"){ echo " checked"; }} ?>><?php echo $lang['login_3']; ?></input>
        </label>
    </p>
    <input type="hidden" id="action" name="action" value="login"></input>
    <p class="submit">
       <input type="submit" value="<?php echo $lang['login_button']; ?>">
    </p>
</form>

When i press the Submit button, $_POST returns: Array ( [login] => Username [password] => Password [action] => login )

But not the checkbox, anyone can help me?

EDIT: I added: name="remember" but still not working.

1
  • @Shannon I rolled-back your edit as you removed the OP's update. Commented Feb 19, 2014 at 22:31

2 Answers 2

8

The problem with checkboxes is, the $_POST value of a checkbox is only set, if the box IS checked. If it is not, the value is not even posted. So you have to use isset() on the expected $_POST variable. If it is not set, the box is not checked. If it is set, you can evaluate the value.

Sign up to request clarification or add additional context in comments.

1 Comment

You're welcome, I had the same problem once and it took me hours to find out :-)
7

Add name too

   <input type="checkbox" id="remember" name="login_remember" <?php if(isset($login_remember)){ if($login_remember == "on"){ echo " checked"; }} ?>><?php echo $lang['login_3']; ?></input>

2 Comments

Small addition: checkboxes do not appear in POST if they are not checked at the moment the form gets submitted.
correct. It seems the name should be login_remember. Please use isset, to see if it was checked

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.