0
Well, I have a form that is validated if the inputs are empty, until then ok, does the validation in the if of all inputs correctly, but with the inputs completed, does not send in Else. Where I went wrong? :/
<form id="contact-form">
<input type="text" name="nome" placeholder="Nome*:" value="" class="required" />
<input type="text" name="telefone" placeholder="Telefone*:" value="" class="required" />
<input type="text" name="email" placeholder="Email*:" value="" class="required" />
<button type="submit" id="enviar" name="submit">Concluir Cadastro</button>
</form>
Js:
$("#contact-form").submit(function(){
event.preventDefault();
var dados = $(this).serialize();
var campos = $(this).find('.required');
$(campos).each(function() {
for(i=0; i=$(this).val() == ''; i++ ){
if( $(this).val() == '' )
{
alert("Preencha os campos obrigatórios");
$(this).focus();
e.preventDefault();
}else {
$.ajax({
type: "POST",
url: "cadastrar.php",
data: dados,
success: function(data)
{
$("#status").slideDown();
$("#status").html(data);
}
});
$('#contact-form').trigger("reset");
}
}
});
});
Jsfiddle: https://jsfiddle.net/sLq1pcbp/