Files
triumf-landing/assets/js/modals.js

47 lines
1.7 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const callbackButtons = document.querySelectorAll('.button--callback');
const callbackModal = document.querySelector('.modal--callback');
const thanksModal = document.querySelector('.modal--thanks');
callbackButtons.forEach((button) => {
button.addEventListener('click', () => {
if (callbackModal) {
callbackModal.classList.add('active');
thanksModal.classList.remove('active');
}
});
});
[callbackModal, thanksModal].forEach((modal) => {
modal.addEventListener('click', (event) => {
const isModal = event.target.classList.contains('modal');
const isModalBody = event.target.classList.contains('modal__body');
if (isModal || isModalBody) event.currentTarget.classList.remove('active');
});
});
const modalForms = document.querySelectorAll('.modal__form');
const callbackForms = document.querySelectorAll('.callback__form');
const BOT_TOKEN = '';
const CHAT_ID = '';
[...modalForms, ...callbackForms].forEach((form) => {
form.addEventListener('submit', (event) => {
event.preventDefault();
const formData = new FormData(event.currentTarget); // автоматически формирует объект с полями и значениями
formData.append('act', 'order'); // добавляем поле для проверки на бекенде
// const name = formData.get('name');
// const phone = formData.get('phone');
// const message = `Имя: ${name} Телефон ${phone}`;
event.currentTarget.reset();
fetch('../../send.php', {
method: 'POST',
cache: 'no-cache',
body: formData,
});
if (callbackModal) callbackModal.classList.remove('active');
if (thanksModal) thanksModal.classList.add('active');
});
});