Answer the question
In order to leave comments, you need to log in
After submitting the form, data instead of variables does not come. Why?
html
<form action="#" id="form" method="GET">
<input type="text" name="fio" placeholder="ФИО*" required>
<input type="text" name="package" placeholder="Пакет*" required>
<input type="text" name="mail" placeholder="E-mail*" required>
<input type="text" name="tel" placeholder="Телефон*" required>
<input type="text" name="code" placeholder="Промокод">
<button class="btn">Зарегистрироваться</button>
</form>
$(document).ready(function() {
$("#form").submit(function() {
$.ajax({
type: "GET",
url: "mail.php",
data: $(this).serialize()
}).done(function() {
$(this).find("input").val("");
alert("Спасибо за заявку! Скоро мы с вами свяжемся.");
$("#form").trigger("reset");
});
return false;
});
});
<?php
$recepient = "[email protected]";
$sitename = "Новый участник";
$fio = trim($_GET["fio"]);
$package = trim($_GET["package"]);
$mail = trim($_GET["mail"]);
$tel = trim($_GET["tel"]);
$code = trim($_GET["code"]);
$message = "ФИО: $fio \nПакет: $package \nE-mail: $mail \nТелефон: $tel \nПромокод: $code";
$pagetitle = "Новая заявка с сайта \"$sitename\"";
mail($recepient, $pagetitle, $message, "Content-type: text/plain; charset=\"utf-8\"\n From: $recepient");
Answer the question
In order to leave comments, you need to log in
try like this:
$(document).ready(function() {
$("#form").submit(function() {
var form = $(this);
$.ajax({
type: "POST",
url: "mail.php",
data: form.serialize()
}).done(function() {
form.find("input").val("");
form.trigger("reset");
alert("Спасибо за заявку! Скоро мы с вами свяжемся.");
});
return false;
});
});
The parameters of the GET request are passed in the URL of the request itself. You put everything in the request body, so $_GET[] does not contain anything on the server side. Those. You need to form a URL like
mail.php?fio="fio"&package="package" etc. Or leave everything as it is, change the request method to POST and take values from $_POST on the server side, respectively.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question