An interesting way to do this is when filling in the e-mail
field you use the change
method of jQuery to send an Ajax.
In PHP it will make a select
checking if this email exists in the database, and if it exists, you can show a message that the email already exists in success
of Ajax.
Example:
var email = $("#email");
email.change(function() {
$.ajax({
url: 'teste.php',
type: 'POST',
data: email.val(),
dataType: 'json',
success: function(data) {
console.log(data);
if (data.email) { // se existir
$("#resposta").append('Ja existe um usuario cadastrado com este email');
}
},
error: function() {
$("#resultado").show().fadeOut(5000);
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type='text' id='email'>
<div id='resposta'></div>
In the php test just returning true to see if the ajax return is working, after that you can do select
and put the appropriate return:
$output = true;
echo json_encode($output);