I am trying to pass a checkbox value of modal form using AJAX but without checking the check-box. Whenever I click on the submit button it automatically selects the checkbox and sends its value. Why is all that happening?
<div class="checkbox">
<label>
<input type="checkbox" name="remember" id="remember" <?php if(isset($_COOKIE['username'])) { ?> checked <?php } ?>>
Remember me
</label>
</div>
$('#login_Modal').click(function(e) {
e.preventDefault();
var username = $('#loginUsername').val();
var password = $('#loginPassword').val();
var remember = $('input[name="remember"]').prop('checked');
if ($("#loginUsername").val() === '') {
$("#loginUsername").parent().addClass('has-error');
$("#loginUsername").focus();
//errCount++;
} else if($("#loginPassword").val() === '') {
$("#loginPassword").parent().addClass('has-error');
$("#loginPassword").focus();
} else {
$("#loginUsername").parent().removeClass('has-error').addClass('has-success');
$.ajax({
url: "form_login_process.php",
type: 'POST',
data: {
'Username': username,
'Password': password,
'Remember' : remember
},
success: function(data) {
alert(data);
}
The AJAX response shows "on"
.
form_login_process.php
<?php
session_start();
require_once './include/db_connection.php';
require_once './functions/functions.php';
$Username = $_POST['Username'];
$Password = $_POST['Password'];
$Remember = $_POST['Remember'];
$sql = "select * from signup where username = '$Username' and password = '$Password'";
$result = mysqli_query($link, $sql);
if(mysqli_num_rows($result)>0)
{
if(!empty($_POST['Remember']))
{
setcookie("username", $Username,time()+ (10 * 365 * 24 * 60 * 60));
setcookie("pass", $Password,time()+ (10 * 365 * 24 * 60 * 60));
}
else
{
//if without clicked on checkbox the cookie still exist then destroy it
if(isset($_POST['Username']))
{
setcookie("username", "", time()-3600);
}
if(isset($_POST['Password']))
{
setcookie("username", "", time()-3600);
}
}
echo 'true';
$_SESSION['username'] = $Username;
}
else
{
echo "false";
}