I need to do a validation in the file field, if it does not have an attachment, show me a message on the screen, forcing it to attach, I tried some alternatives and I 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 Work With Us option.
In js it looks like this:
// 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();
});
});