1
Good morning, I’m trying to make a check if the typed Cpf already exists in the bank, I’m using Portable, could someone help me in this function please?
In my controller I search and list all the database numbers:
$cpfduplicado = UsuarioEsic::lists('doc', 'id')->all();
foreach ($cpfduplicado as $cpf)
if ($cpf == $request->cpf)
$cpf = 'verdadeiro';
// return redirect('/Esic/CadastroFisica');
return redirect('/Esic/Sucesso');
I don’t know very well how to do a function in javascript to take this data and set a custom browser validity, I did something like this:
$(function cpfdupli(input) {
$('.btnCadastroo').on('click', function (json){
if (json.cpf === 'verdadeiro'){
document.getElementById('cpff');
input.setCustomValidity('Cpf já existe.');
} else {
input.setCustomValidity('');
}
});
});
I’m a beginner in the business and I don’t really know how to make it work, I just wish that if Cpf already existed set a Customvalidity in the browser and didn’t let it continue with the registration, if anyone can help me or give me other ways to resolve this I would be very grateful !
Note: Any questions about the code will be available to provide.
like the
browser
customer does not have access toMySQL
on your server, theJavaScript
will not consult theMySQL
(still good), then you will need to make a request usingAJAX/XMLHttpRequest
and return an object using the methodjson_encode
.– Tobias Mesquita
But who queries mysql is my controller, I just need to play the controller information for javascript and then check if the typed Cpf is equal to any of the Cpf’s listed by the controller and then set a browser function.
– Lincoln Binda
The only link between your PHP controller and the client page is the HTTP requests (although spaghetti written by some PHP programmers gives the impression that PHP has some link with HTML and Javascript), so my comment remains.
– Tobias Mesquita
Licoln, read the following link: How to change status with AJAX?, has a step by step how to make a request
AJAX
, the use ofjson_encode
and how to read the return json and update the client page.– Tobias Mesquita
Man, thank you so much, I was at lunch, I’ll study it right now, thank you !
– Lincoln Binda