0
I have a contact form using Phpmailer which in one project worked perfectly. All return messages were done using CSS only, without Javascript. But now, in this new project, I want to use JS to make the messages look more beautiful.
So I used the following JS:
// Contact form
var form = $('#main-contact-form');
form.submit(function (event) {
event.preventDefault();
var form_status = $('<div class="form_status"></div>');
$.ajax({
url: $(this).attr('action'),
beforeSend: function () {
form.prepend(form_status.html('<p>Enviando Email...</p>').fadeIn());
}
}).done(function (data) {
form_status.html('<p class="text-success">Obrigado por entrar em contato!</p>').delay(3000).fadeOut();
});
});
When I send the form, the message appears "Thank you for contacting!" with the effect of delay and fadeOut, but does not send anything. Now, if I remove the Event.preventDefault(), the same message appears, only quickly (without the delay) and send the form with all data.
I wonder where the problem is?
Sérgio, unfortunately not solved, he sends the form but does not properly apply the delay. The problem here is only in delay
– Fabricio Marra
@Fabriciomarra can explain how and where these 3 sentences should appear. This is simple, explains that correct the answer
– Sergio