0
I’m making a form that checks if the number already exists in a database. In my JS I use the Jquery Validate library
$('#form').validate({
rules:{
cpf: {
required: true,
cpfBR: true,
remote: "cpfunico.php"
},
},
messages: {
cpf: {
remote: "CPF já cadastrado."
}
},
});
In the Serverside file I have the following request:
if(procuraCpf($_GET['cpf'])){
echo true;
// ja tentei também com echo (json_encode(true));
} else {
echo false;
}
The function procuraCpf() returns whether it found Cpf in the database and returns to Jquery via a true or false message.
The problem is when the server returns an already registered Cpf, and gives the message via Validate. After that all the Cpf s will give the message "CPF already registered". I inspected the code and identified that Jquery Validate sends the message even before making the request in the database to see if Cpf exists. I don’t understand why this happens.
Have you tried in this way?
– Valdeir Psr
Yes, but the problem remains.
– Rafael Christófano
Substitute
echo true;
forecho "true";
. The same withfalse
– Valdeir Psr
Have you solved your problem? I’m facing the same problem
– Sérgio Machado
I couldn’t reach friend. I’m validating Cpf when the user saves the form. When I can do this, I will apply in the next version of the system.
– Rafael Christófano