Answer the question
In order to leave comments, you need to log in
How to remove the redirect to the send file when submitting the form?
On the site johny-gyro.ru , the form is sent by Ajax, that is, without reloading the page.
But there is a separate place where it does not work - the product window on all three products, after sending the site immediately redirects to the sender's php file, which is specified in the action. (the product window itself is made with jquery product quick view)
Here is the form:
<form method="POST" class="mail-to" action="mail.php">
<input type="text" name="phone" required placeholder="Телефон">
<input class="my-btn yellow-my-btn" type="submit" value="Отправить">
</form>
$("form").submit(function(e) { //устанавливаем событие отправки для формы с id=form
e.preventDefault();
var form = $(this);
var form_data = $(this).serialize(); //собераем все данные из формы
$.ajax({
type: "POST", //Метод отправки
url: form.attr('action'), //путь до php фаила отправителя
data: form_data,
success: function() {
// yaCounter43092004.reachGoal(goal);
//код в этом блоке выполняется при успешной отправке сообщения
$('#thankyouModal').modal('show');
form[0].reset();
}});
});
<?php
// несколько получателей
$to = '[email protected]'; // обратите внимание на запятую
// тема письма
$subject = 'Заявка на сайте johny-gyro (' . date("Y-m-d H:i:s") . ')';
// текст письма меняется он!!
$message = '' . $_POST['phone'];
// Для отправки HTML-письма должен быть установлен заголовок Content-type
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'Content-Transfer-Encoding: 8bit' . "\r\n";
// Дополнительные заголовки
$headers .= 'To: info <[email protected]>' . "\r\n"; // Свое имя и email
$headers .= 'From: [email protected] ' . "\r\n";
// Отправляем
mail($to, $subject, $message, $headers);
?>
Answer the question
In order to leave comments, you need to log in
where is the code for all forms? may not be specified type submit .. little information
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question