ludvik120 ludvik120 - 20 days ago 5
PHP Question

How to pass checbox value via AJAX,PHP?

I have a simple login form with checbox remember me. What i want to achieve is when user checked checbox than create cookies else start session but it still start session even I checked checkbox. Can anyone help ?

This is my html:

<form action="PHP/login.php" method="post" class="loginForm">

<div class="form_vkope">
<input type="text" name="prihlNick" placeholder="Nick" class="prihlNick" />
<img src="Obrazky/ios7-person.png" alt="Ikonka postavy">

<div class="form_vkope">
<input type="password" name="prihlHeslo" placeholder="Heslo" class="prihlHeslo" />
<img src="Obrazky/locked.png" alt="Ikonka zámok">

<div class="obal_submitov">
<input type="checkbox" name="zapametat" class="zamapetat" /><label for="zapametat"><span></span>Remember me</label>
<input type="submit" name="prihlasit" value="Login" class="prihlasit" />

part of my PHP:

$zapametat = $_POST['zapametat']; //checkbox
if ($dbNick == $Snick AND $dbHeslo == $Sheslo) {
if ($ban != 1) {
if (isset($zapametat)) {
setcookie('id',$dbId,time()+86400, '/');
setcookie('nick',$dbNick,time()+86400, '/');
echo "cookie";
$_SESSION['id'] = $dbId;
$_SESSION['nick'] = $dbNick;
echo "session";
echo "Tvoj účet bol zablokovaný";
echo "Heslo alebo meno sa nezhoduje";

And my jQuery:

$('.prihlasit').click(function() {
var prihlNick = $('.prihlNick').val();
var prihlHeslo = $('.prihlHeslo').val();
var prihlasit = $('.loginForm .prihlasit');
var checbox = $('.zapametat'); //checkbox
var data = 'prihlNick='+prihlNick+'&prihlHeslo='+prihlHeslo+'&zapametat='+checbox+'&prihlasit='+prihlasit;
if (prihlNick == '' || prihlHeslo == '') {
$('.loginForm :input').addClass('inputError');
$('.loginForm :input').removeClass('inputError');
url: 'PHP/login.php',
type: 'POST',
data: data ,
.done(function(data) {


I would suggest using this:


var checbox = $('.zapametat').prop('checked'); //checkbox (jQuery 1.6+)