-2
I am trying to sketch as in the image below the mistakes committed by erroneous data entry in the form. However, it only works when data is entered correctly.
The javascript code is
$("#formCadastro").on("submit", function (event) {
event.preventDefault();
var dados = $(this).serialize();
$.ajax({
url: getRoot() + 'controllers/controllerCadastro',
type: "POST",
dataType: "json",
data: dados,
success: function (xhr) {
$(".retornoCad").empty();
$(".retornoCad").append("Dados inseridos com sucesso!");
},
error: function (xhr) {
$(".retornoCad").empty();
getCaptcha();
$.each(xhr.response, function(key,value){
$(".retornoCad").append(value + '<br>');
});
}
});
});
And the validation . php is
public function validateFinalCad($arrVar)
{
if (count($this->getErro()) > 0) {
$arrResponse = [
// print_r($this->getErro())
"retorno" => "erro",
"erros" => print_r($this->getErro())
];
} else {
$arrResponse = [
// print_r($this->getErro())
"retorno" => "success",
"erros" => null
];
/*$this->cadastro->insertCad($arrVar);*/
}
return json_encode($arrResponse);
}
If the validation response returns an HTTP response status 4**, 5** (example 422,500) then you can validate it by error : . See developer tools > network > XHR for response and code. Also check Success and error using console.log(xhr) to debug messages etc.
– Marcos Xavier
Important you [Dit] your question and explain objectively and punctually the difficulty found, accompanied by a [mcve] of the problem and attempt to solve. To better enjoy the site, understand and avoid closures and negativations worth understanding What is the Stack Overflow and read the Stack Overflow Survival Guide (summarized) in Portuguese.
– Bacco
I will re-edit. But the problem is simple, so I didn’t write as much.
– Rodolfo Fernandes