I'm making a form that checks whether the CPF 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 requisition:
if(procuraCpf($_GET['cpf'])){
echo true;
// ja tentei também com echo (json_encode(true));
} else {
echo false;
}
The search function Cpf () returns if found cpf in the database and returns to JQuery with a true or false message.
The problem is when the server returns a cpf already registered, 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 issues the message before it even requests the database to see if the cpf exists. I do not understand why this happens.