Email appraisal

Asked

Viewed 48 times

1

I have a problem analyzing the email on form registration, what I would like to do is that as soon as the user insert his email in the field email, the site already evaluate the email in the database to know if it is available to perform the registration. And otherwise, inform below that the email is unavailable.

Someone could tell me the process to do this?

  • 2

    And what have you done? What is your specific question?

  • What I was able to do to solve the problem, was using another file to validate the registration, which checks if the email already exists in the database via php, if it exists back to the registration screen. But I’m looking for a way to evaluate the email as soon as the user fills in the email input in the registration form, without having to click the "register" button of the form to call the file that validates the registration.

  • @Vynstus, you are willing to use Jquery for this purpose ?

1 answer

1


I needed it and I developed it:

jQuery:

var email = $("#usuario_email");
    email.blur(function() {
        $.ajax({ 
            url: "/outras/verificaEmail.php",
            method: "POST",
            cache: false,
            data: {"usuario_email": $("#usuario_email").val()},
            dataType: "json",       
            success: function(data) {
                console.log("usuario_email");
                console.log(data);
                $("#resposta").text(data.email);
            },
            error: function(a, b, c) {
                console.log(a);
                console.log(b);
                console.log(c); 
            }
    }); 
}); 

HTML:

<label for="inputType" class="col-md-2 control-label">E-mail de Acesso</label>
<div class="col-md-4">
    <input type="email" class="form-control" id="usuario_email" name="usuario_email" placeholder="Digite seu E-mail">
    <div id='resposta'></div>
</div>

PHP:

#Verifica se tem um email para pesquisa
if(isset($_POST['usuario_email'])){

    #Recebe o Email Postado
    $emailPostado = $_POST['usuario_email'];

    #Conecta banco de dados
    $con = mysqli_connect("localhost", "root", "", "outras");
    $sql = mysqli_query($con, "SELECT * FROM cadastrousuarios WHERE usuario_email = '{$emailPostado}'") or print mysql_error();

    #Se o retorno for maior do que zero, diz que já existe um.
    if(mysqli_num_rows($sql)>0){
        echo json_encode(array('email' => 'Ja existe um usuário cadastrado com este email.'));
    } else { 
        echo json_encode(array('email' => 'Parabéns! Você poderá usar este e-mail como usuário.' ));
    }
}

I believe it’s the most compatible solution at the moment I know to help you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.