Answer the question
In order to leave comments, you need to log in
How to correctly set up sending data from several different forms on one page?
Hello,
I set up sending data from the form on the html page :
<form method="post" action="javascript:void(0);" onsubmit="send_form();" id="forma">
<input id="name1" name="fio" placeholder="Ф.И.О" />
<input id="phone1" type="text" name="phone" placeholder="Телефон" />
<input id="age1" type="text" name="age" placeholder="Возраст девочки" />
<input id="adress1" type="text" name="adress" placeholder="Адрес зала" />
<textarea id="comment1" name="comment" type="text" placeholder="Комментарий"></textarea>
<br/>
<button type="submit" id="submit1" value="отправить" /> Записаться </button>
</form>
<!-- отправка формы -->
<script>
function send_form() {
var msg = $("#forma").serialize();
$.ajax({
type: "POST",
url: "/wp-content/themes/gymbalance/send.php",
data: msg,
success: function(data) {
alert("Сообщение отправлено");
setTimeout(function () {
$(".feedback_form_bg").fadeOut();}, 1000);
},
error: function(xhr, str){
alert("Возникла ошибка!");
setTimeout(function () {$(".feedback_form_bg").fadeOut();}, 1000);
}
});
}
</script>
<?php
$fio= $_POST['fio'];
$phone= $_POST['phone'];
$age= $_POST['age'];
$adress= $_POST['adress'];
$comment= $_POST['comment'];
$emailTo = '[email protected]'; //Сюда введите Ваш email
$body = "ФИО: $fio \n\nТелефон: $phone\n\nВозраст: $age \n\nАдрес зала: $adress \n\nКомментарий: $comment";
$headers = "Content-Type: text/plain; charset=utf-8\r\n".'From: Заявка с сайта <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $emailTo;
mail($emailTo, $fio, $body, $headers);
$emailSent = true;
?>
Answer the question
In order to leave comments, you need to log in
In general, the form - should be an abstract element, it makes sense to combine them into one form if they are all sent at the same time.
But you can add any value
instead of a string
var msg = $("#forma").serializeArray();
msg.push({
name: "example1",
value: $("#forma [name=example1]").val()
});
msg.push({
name: "example2",
value: $("#forma [name=example2]").val()
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question