2
I need to do a validation in the field file, in case it has no attachment show me a message on the screen forcing to attach, I tried some alternatives and could not.
<div class="form-group" id="inputOculto">
<input name="arquivo" type="file" class="form-control-anexo" input/>
</div>
This field only appears if in the subject I select the option Work with us.
No js this so:
// Contact form com anexo e sem anexo
var form = $('#main-contact-form');
form.submit(function(event){
event.preventDefault();
var data;
var form_status = $('<div class="form_status"></div>');
data = $("#main-contact-form").serialize();
$.ajax({
type: "POST",
url: $(this).attr('action'),
data: new FormData(this),
processData: false,
contentType: false,
beforeSend: function(){
if ($('#mySelect').val() == 'Trabalhe Conosco')
{
if ($('#arquivo').val() == null)
{
alert("É Obrigatório Anexar Seu Currículo!" );
}
}
else
{
form.prepend( form_status.html('<p><i class="fa fa-spinner fa-spin"></i> Enviando Mensagem...</p>').fadeIn() );
}
}
}).done(function(data){
form_status.html('<p class="text-success">Mensagem enviada. O mais breve possível retornaremos o contato.</p>').delay(9000).fadeOut();
});
});
Thank you very much, it worked perfectly.
– William Demski
Not at all, friend! If you think the answer is better, you can mark and/or give a positive vote if you wish. Obg!
– Sam