Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML/PHP Checkbox not working

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.

like image 321
mlomb Avatar asked Dec 06 '22 03:12

mlomb


1 Answers

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.

like image 144
Roxxorfreak Avatar answered Dec 08 '22 18:12

Roxxorfreak