I want to edit the error message outside of the validate function. So I have a simple password recovery form. Here's the html:
<div style="position:relative; left:40%;" class="pass_recovery">
<h2 class="title">Recover</h2>
<form action="" method="POST" id="recover_pass">
<span style="font-size:12px;">Email you registered with: </span><input type="text" name="recov_pass" id="recov_pass"<br>
<input type="submit" value="Send Password">
</form><br>
</div>
And here's my jquery for the validation:
var pass_rec = $('#recover_pass').validate({
onkeyup: false,
errorClass: "password_messages",
rules: {
recov_pass: {
required: true,
email: true
}
},
messages: {
recov_pass: {
required: "Please enter an email address",
email: "Please enter a valid email address"
}
}
});
And then the ajax call. This simply checks if the inputted email is a valid, registered email address.
$('#recover_pass').submit(function() {
if(pass_rec.form()) {
var $this = $(this);
$.ajax({
data: $this.serialize(), // get the form data
type: "POST", // GET or POST
url: "Private/Recover_pass.php", // the file to call
success: function(data) { // on success..
if(data=="pass") {
$('.password_messages').text('good');
}
else {
$('.password_messages').text('bad');
}
},
error: function(data) {
$('.password_messages').text('error');
},
complete: function(data) {
$('#recov_pass').val("");
}
});
}
return false; //so it doesn't refresh when submitting the page
});
This doesn't work because when I entered in a dummy email that isn't registered, say [email protected], then it doesn't display the bad message. How do I show the error message outside of the validation function?
console.log(data)inside your success function<p>that I would do.text(data)on and it would display just fine.