Yaroslav Vendysh
asked on
php ajax contact form gives me undefined index error upon submission
When i try get ehco from php to ajax, all time i get "Baddd".
Why isset($data['do_login']) all time false?!
Name button is normal..
If i delete ajax function and add in form action="demo.php", then after submit form open new window(demo.php) and write "good".
But with ajax it doesnt work :(
It say error: Undefined index: do_login in demo.php on line 6, but why?!
Help pls
Why isset($data['do_login']) all time false?!
Name button is normal..
If i delete ajax function and add in form action="demo.php", then after submit form open new window(demo.php) and write "good".
But with ajax it doesnt work :(
It say error: Undefined index: do_login in demo.php on line 6, but why?!
Help pls
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myModalLabel">Увійти</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×
</span>
</button>
</div>
<div class="modal-body">
<form method="POST" class="js-form" id="popupResult">
<input type="email" name="email" class="form-control" required=""
placeholder="Електронна адреса">
<input type="password" name="password" class="form-control" required=""
placeholder="Пароль">
<label>
<input type="checkbox" name="option1">
Запам'ятати мене
</label>
<input type="submit" value="Submit" id="do_login" name="do_login"/>
</form>
</div>
<div class="modal-footer">
<!-- <a href="" class="mr-auto ml-auto">
Не отримали листа-підтвердження?
</a> -->
<div id="result"></div>
</div>
</div>
</div>
</div>
$("#do_login").click( function() {
$.ajax({
type: "POST",
//dataType: "html",
data: $("#popupResult").serialize(),
url: 'demo.php',
success: function(data) {
alert(data);
//$("#result").text(data);
//alert(data);
//if (data == true) $("#myModal").modal('hide');
//if (data == false) $("#result").text("Bad");
//$("#myModal").modal('hide');
}
});
$("#popupResult").submit( function() {
return false;
});
});
<?php
require "db.php";
$data = $_POST;
echo $_POST["do_login"];
echo $_POST["email"];
echo $_POST["password"];
if(isset($data['do_login']))
{
$errors = array();
$user = R::findOne('login', 'email = ?', array($data['email']));
if($user)
{
if (password_verify($data['password'], $user->password))
{
$_SESSION['logged_user'] = $user;
//echo '<div style="color:green;">Easy</div>';
echo "good";
}
else
{
$errors[] = 'Неправильно введения пароль';
}
}
else
{
$errors[] = 'Користувача з таким логіном не існує';
}
if(!empty($errors))
{
//echo '<div style="color:red;">'.array_shift($errors).'</div>';
echo "er";
}
} else echo "Baddd";
?>
ASKER
on Chrome, do a right click on this do_login button and choose inspect to check what is going on
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you:)
replace your demo.php by :
Open in new window
maybe your form is malformed