I have the following form which process a password recovery script requested by the user.
<form class="forget-form" id="forget-form" action="datacenter/functions/passwordRecovery.php" method="POST">
<h3 class="font-green">Esqueceu sua senha?</h3>
<p> Digite seu e-mail abaixo para receber o procedimento para uma nova senha.</p>
<div class="form-group" style="margin-bottom:0px">
<input class="form-control placeholder-no-fix" type="email" autocomplete="off" placeholder="Seu e-mail" name="email" id="email" required/>
</div>
<div class="form-actions">
<button type="button" id="back-btn" class="btn red btn-outline uppercase"><i class="fa fa-chevron-circle-left"></i> voltar</button>
<button type="submit" class="btn btn-success uppercase pull-right uppercase"><i class="fa fa-paper-plane"></i> enviar</button>
</div>
</form>
For that, I'm using ajax to keep the user on the same screen without any redirect.
$("#forget-form").submit(function(e){
e.preventDefault();
var email = $("#email").val();
if(isEmail(email) == true){
$.ajax({
url: 'datacenter/functions/passwordRecovery.php',
type: 'POST',
data: new FormData(this),
async: true,
contentType: false,
processData: false,
success: function(data){
console.log(data);
},
error: function(error, errorThrown, errorShowcase){
console.log(data);
}
});
} else {
console.log('this is not an email');
}
});
The file passwordRecovery.php only echo "success"; to log on the console, just to check if it really worked, and it is working, but too fast, it logs on the console and after that redirects me to passwordRecovery.php, not preventing the default action of the form.
Have you ever faced that?