style: add some style 5 (modal form 3)

This commit is contained in:
2026-06-05 12:17:18 +03:00
parent 9e006c2572
commit 24824e2dc3
2 changed files with 63 additions and 48 deletions

View File

@@ -821,61 +821,72 @@
<script>
// === МОДАЛЬНОЕ ОКНО + ОТПРАВКА ===
const popup = document.getElementById('booking-popup');
const form = document.getElementById('popup-booking-form');
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) {
e.preventDefault();
if (popup && form) {
const openModal = () => {
popup.classList.add('modal--active');
});
});
popup.setAttribute('aria-hidden', 'false'); // ← исправление
// Перевод фокуса на первое поле
setTimeout(() => {
form.querySelector('input').focus();
}, 300);
};
// Закрытие
document.querySelectorAll('[data-modal-close]').forEach(el => {
el.addEventListener('click', () => {
const closeModal = () => {
popup.classList.remove('modal--active');
});
});
popup.setAttribute('aria-hidden', 'true');
};
// Отправка формы
form.addEventListener('submit', async function(e) {
e.preventDefault();
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
// Открытие
document.querySelectorAll('a[href="#booking"], .btn[href="#booking"]').forEach(btn => {
btn.addEventListener('click', function(e) {
e.preventDefault();
openModal();
});
});
const result = await response.json();
// Закрытие
document.querySelectorAll('[data-modal-close]').forEach(el => {
el.addEventListener('click', closeModal);
});
if (result.status === "success") {
alert("✅ Заявка успешно отправлена!\nМы свяжемся с вами в ближайшее время.");
form.reset();
popup.classList.remove('modal--active');
} else {
alert("❌ " + (result.message || "Ошибка при отправке. Попробуйте позже."));
// Отправка формы (оставь как было, только добавь closeModal() при успехе)
form.addEventListener('submit', async function(e) {
e.preventDefault();
const submitBtn = form.querySelector('button[type="submit"]');
const originalText = submitBtn.textContent;
submitBtn.textContent = 'Отправляем...';
submitBtn.disabled = true;
try {
const response = await fetch('send-form.php', {
method: 'POST',
body: new FormData(form)
});
const result = await response.json();
if (result.status === "success") {
alert("✅ Заявка успешно отправлена!\nМы свяжемся с вами в ближайшее время.");
form.reset();
closeModal(); // ← используем функцию
} else {
alert("❌ " + (result.message || "Ошибка при отправке."));
}
} catch (error) {
console.error(error);
alert("❌ Ошибка соединения.");
}
} catch (error) {
console.error(error);
alert("❌ Ошибка соединения. Проверьте интернет и попробуйте снова.");
}
submitBtn.textContent = originalText;
submitBtn.disabled = false;
});
}
submitBtn.textContent = originalText;
submitBtn.disabled = false;
});
}
</script>