I have index.php inside in this has modal window with login link. Modal window is with username and password checking in mysql with php. But when I clicked submit button- no typing
username or password it’s not showing php errors – ‘You need to enter a username’ or ‘You need to enter a password’…When is refreshing index.php and I clicked login link it is showing …
How I can resolve this problem on first click on submit button is cheking for mysql php error?
<div id="basic-modal-content">
<div id="winsign">
<form action="" method="post" onSubmit="validate();">
<?php
include 'core/init.php';
if (empty($_POST) === false) {
$username = $_POST['username'];
$password = $_POST['password'];
if (empty($username) === true || empty($password) === true) {
$errors[]= 'You need to enter a username and password';
} else if (user_exists($username) === false) {
$errors[]= 'We cant\'t find username. Have you registered?';
} else if (user_active($username) === false) {
$errors[]= 'You haven\'t acticated your account!';
} else {
$login = login($username, $password);
if ($login === false) {
$errors[] = 'That username/password combination is incorrect';
} else {
$_SESSION['user_id'] = $login;
header('Location: sign_in.php');
exit();
}
}
print_r($errors);
}
?>
<span id="tpos">Username:</span><br>
<input type="text" name="username" class="sbutton" id="modalbox" placeholder="Username">
<br><br><span id="tpos">Password:</span>
<br><input type="password" name="password" class="sbutton" id="modalbox" placeholder="Password">
<br><br><input type="checkbox" name="checkbox" class="cbutton"><span id="ttext">Remember me</span>
<br><input type="submit" value="Sign In" name="signin" id="bsubmit">
</input>
</form>
That is in modal window and when i clicked submit button is not checking for php errors in first click and reload index.php When i clicked second time is there error but in first click is not showing errors and reload page index…
I think you’re looking for an onSubmit for your form.
Try something like this: