Compare commits
2 Commits
82529bed91
...
0ba1b74876
| Author | SHA1 | Date | |
|---|---|---|---|
| 0ba1b74876 | |||
| 9e006c2572 |
53
index.html
53
index.html
@@ -820,27 +820,62 @@
|
|||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// Открытие модального окна
|
// === МОДАЛЬНОЕ ОКНО + ОТПРАВКА ===
|
||||||
document.querySelectorAll('[href="#booking"], .btn[href="#booking"]').forEach(btn => {
|
const popup = document.getElementById('booking-popup');
|
||||||
|
const form = document.getElementById('popup-booking-form');
|
||||||
|
|
||||||
|
if (popup && form) {
|
||||||
|
// Открытие окна
|
||||||
|
document.querySelectorAll('a[href="#booking"], .btn[href="#booking"]').forEach(btn => {
|
||||||
btn.addEventListener('click', function(e) {
|
btn.addEventListener('click', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
document.getElementById('booking-popup').classList.add('modal--active');
|
popup.classList.add('modal--active');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Закрытие
|
// Закрытие
|
||||||
document.querySelectorAll('[data-modal-close]').forEach(el => {
|
document.querySelectorAll('[data-modal-close]').forEach(el => {
|
||||||
el.addEventListener('click', () => {
|
el.addEventListener('click', () => {
|
||||||
document.getElementById('booking-popup').classList.remove('modal--active');
|
popup.classList.remove('modal--active');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Закрытие по Esc
|
// Отправка формы
|
||||||
document.addEventListener('keydown', e => {
|
form.addEventListener('submit', async function(e) {
|
||||||
if (e.key === "Escape") {
|
e.preventDefault();
|
||||||
document.getElementById('booking-popup').classList.remove('modal--active');
|
|
||||||
}
|
const submitBtn = form.querySelector('button[type="submit"]');
|
||||||
|
const originalText = submitBtn.textContent;
|
||||||
|
|
||||||
|
submitBtn.textContent = 'Отправляем...';
|
||||||
|
submitBtn.disabled = true;
|
||||||
|
|
||||||
|
const formData = new FormData(form);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch('send-form.php', {
|
||||||
|
method: 'POST',
|
||||||
|
body: formData
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
|
||||||
|
if (result.status === "success") {
|
||||||
|
alert("✅ Заявка успешно отправлена!\nМы свяжемся с вами в ближайшее время.");
|
||||||
|
form.reset();
|
||||||
|
popup.classList.remove('modal--active');
|
||||||
|
} else {
|
||||||
|
alert("❌ " + (result.message || "Ошибка при отправке. Попробуйте позже."));
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
alert("❌ Ошибка соединения. Проверьте интернет и попробуйте снова.");
|
||||||
|
}
|
||||||
|
|
||||||
|
submitBtn.textContent = originalText;
|
||||||
|
submitBtn.disabled = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,32 +1,39 @@
|
|||||||
<?php
|
<?php
|
||||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
$name = strip_tags(trim($_POST["name"]));
|
|
||||||
$phone = strip_tags(trim($_POST["phone"]));
|
|
||||||
$email = strip_tags(trim($_POST["email"]));
|
|
||||||
|
|
||||||
//$to = "receptionadmin@o-arena.ru"; // поменяй на свой реальный email
|
if ($_SERVER["REQUEST_METHOD"] !== "POST") {
|
||||||
$to = "rid89@mail.ru"; // поменяй на свой реальный email
|
echo json_encode(["status" => "error", "message" => "Неверный запрос"]);
|
||||||
$subject = "Новая заявка с сайта OlimpArena";
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
$message = "Имя: $name\n";
|
$name = trim(strip_tags($_POST["name"] ?? ""));
|
||||||
$message .= "Телефон: $phone\n";
|
$phone = trim(strip_tags($_POST["phone"] ?? ""));
|
||||||
$message .= "Email: $email\n";
|
$email = trim(strip_tags($_POST["email"] ?? ""));
|
||||||
$message .= "Дата отправки: " . date('d.m.Y H:i') . "\n";
|
|
||||||
|
|
||||||
$headers = "From: no-reply@olimparena.aiconversion.ru\r\n";
|
if (empty($name) || empty($phone)) {
|
||||||
$headers .= "Reply-To: $email\r\n";
|
echo json_encode(["status" => "error", "message" => "Имя и телефон обязательны"]);
|
||||||
$headers .= "Content-Type: text/plain; charset=utf-8\r\n";
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
if (mail($to, $subject, $message, $headers)) {
|
//$to = "receptionadmin@o-arena.ru"; // ← Измени на свой реальный email!
|
||||||
// Можно перенаправить на успех
|
$to = "rid89@mail.ru";
|
||||||
header("Location: index.html#booking-success-modal");
|
|
||||||
// или показать JSON для JS
|
$subject = "Новая заявка с сайта OlimpArena";
|
||||||
|
|
||||||
|
$message = "📩 Новая заявка из всплывающего окна\n\n";
|
||||||
|
$message .= "Имя: $name\n";
|
||||||
|
$message .= "Телефон: $phone\n";
|
||||||
|
$message .= "Email: $email\n\n";
|
||||||
|
$message .= "Дата: " . date('d.m.Y H:i:s') . "\n";
|
||||||
|
|
||||||
|
$headers = "From: no-reply@olimparena.aiconversion.ru\r\n";
|
||||||
|
$headers .= "Reply-To: $email\r\n";
|
||||||
|
$headers .= "Content-Type: text/plain; charset=utf-8\r\n";
|
||||||
|
|
||||||
|
if (mail($to, $subject, $message, $headers)) {
|
||||||
echo json_encode(["status" => "success"]);
|
echo json_encode(["status" => "success"]);
|
||||||
} else {
|
|
||||||
echo json_encode(["status" => "error"]);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
http_response_code(403);
|
error_log("Mail error: " . print_r(error_get_last(), true));
|
||||||
echo "Доступ запрещён";
|
echo json_encode(["status" => "error", "message" => "Не удалось отправить письмо"]);
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
Reference in New Issue
Block a user