Just look at my problem. I have a normal contact form using PHPMailer which in one project worked perfectly, all return messages were using CSS only, without JS. But now in this new project I want to use a JS to make the messages look nicer.
Then 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 submit the form, the message Thanks for contacting me! appears with the effect of delay and fadeOut , but does not send anything Now, if I remove the event.preventDefault () it will display the same message, only fast, without using the delay and send the form with all the data. p>
Where is the problem?