diff --git a/app/templates/login.html b/app/templates/login.html index f386925..41b8648 100644 --- a/app/templates/login.html +++ b/app/templates/login.html @@ -193,11 +193,19 @@ } async function submitForm() { - const name = document.getElementById('am-name').value.trim(); - const company = document.getElementById('am-company').value.trim(); - const email = document.getElementById('am-email').value.trim(); - const phone = document.getElementById('am-phone').value.trim(); - const manager = document.getElementById('am-manager').value.trim(); + const nameEl = document.getElementById('am-name'); + const companyEl = document.getElementById('am-company'); + const emailEl = document.getElementById('am-email'); + const phoneEl = document.getElementById('am-phone'); + const managerEl = document.getElementById('am-manager'); + const submitBtn = document.getElementById('am-submit'); + const errorEl = document.getElementById('am-error'); + + const name = nameEl ? nameEl.value.trim() : ''; + const company = companyEl ? companyEl.value.trim() : ''; + const email = emailEl ? emailEl.value.trim() : ''; + const phone = phoneEl ? phoneEl.value.trim() : ''; + const manager = managerEl ? managerEl.value.trim() : ''; const checked = [...document.querySelectorAll('#am-products input[type=checkbox]:checked')]; const products = checked.map(c => c.value); @@ -205,31 +213,25 @@ const phoneRe = /^[\+\d][\d\s\-\(\)]{6,18}$/; const fields = [ - { el: document.getElementById('am-name'), val: name, check: () => !!name, msg: 'Введите имя и фамилию' }, - { el: document.getElementById('am-company'), val: company, check: () => !!company, msg: 'Введите название компании' }, - { el: document.getElementById('am-email'), val: email, check: () => emailRe.test(email), msg: 'Введите корректный email' }, - { el: document.getElementById('am-phone'), val: phone, check: () => phoneRe.test(phone), msg: 'Введите корректный номер телефона' }, + { el: nameEl, check: () => !!name, msg: 'Введите имя и фамилию' }, + { el: companyEl, check: () => !!company, msg: 'Введите название компании' }, + { el: emailEl, check: () => emailRe.test(email), msg: 'Введите корректный email' }, + { el: phoneEl, check: () => phoneRe.test(phone), msg: 'Введите корректный номер телефона' }, ]; const errors = []; fields.forEach(f => { - if (!f.check()) { - f.el.classList.add('am-invalid'); - errors.push(f.msg); - } else { - f.el.classList.remove('am-invalid'); - } + if (f.el && !f.check()) { f.el.classList.add('am-invalid'); errors.push(f.msg); } + else if (f.el) f.el.classList.remove('am-invalid'); }); if (errors.length) { - errEl.textContent = errors.join(' • '); - errEl.style.display = 'block'; + if (errorEl) { errorEl.textContent = errors.join(' • '); errorEl.style.display = 'block'; } return; } - btnSubmit.disabled = true; - btnSubmit.textContent = 'Отправка...'; - errEl.style.display = 'none'; + if (submitBtn) { submitBtn.disabled = true; submitBtn.textContent = 'Отправка...'; } + if (errorEl) errorEl.style.display = 'none'; try { const res = await fetch('/api/request-access', { @@ -241,10 +243,8 @@ const d = await res.json().catch(() => ({})); throw new Error(d.detail || 'Ошибка отправки'); } - btnSubmit.textContent = 'Отправлено!'; - // Show success message - const body = document.querySelector('.access-modal-body'); - const footer = document.querySelector('.access-modal-footer'); + const body = document.querySelector('#access-modal .access-modal-body'); + const footer = document.querySelector('#access-modal .access-modal-footer'); body.innerHTML = '