Lisää yhteydenottolomakkeen PHP-backend ja vaihda sähköposti
- send.php: lomake lähettää sähköpostin box@storagebox.fi:hin - script.js: lomake POSTaa send.php:lle async/await:lla - Vaihdettu info@storagebox.fi -> box@storagebox.fi - Validointi, header injection -suojaus, UTF-8 tuki Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
37
script.js
37
script.js
@@ -51,19 +51,40 @@ document.querySelectorAll('.feature-card, .pricing-card, .contact-info-card, .se
|
||||
const contactForm = document.getElementById('contactForm');
|
||||
const formStatus = document.getElementById('formStatus');
|
||||
|
||||
contactForm.addEventListener('submit', (e) => {
|
||||
contactForm.addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
const formData = new FormData(contactForm);
|
||||
const data = Object.fromEntries(formData);
|
||||
const submitBtn = contactForm.querySelector('button[type="submit"]');
|
||||
const originalText = submitBtn.textContent;
|
||||
submitBtn.textContent = 'Lähetetään...';
|
||||
submitBtn.disabled = true;
|
||||
|
||||
// For now, show success message (backend can be added later)
|
||||
formStatus.className = 'form-status success';
|
||||
formStatus.textContent = 'Kiitos viestistäsi! Palaamme asiaan mahdollisimman pian.';
|
||||
try {
|
||||
const formData = new FormData(contactForm);
|
||||
const response = await fetch('send.php', {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
});
|
||||
|
||||
contactForm.reset();
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
formStatus.className = 'form-status success';
|
||||
formStatus.textContent = result.message;
|
||||
contactForm.reset();
|
||||
} else {
|
||||
formStatus.className = 'form-status error';
|
||||
formStatus.textContent = result.message;
|
||||
}
|
||||
} catch (error) {
|
||||
formStatus.className = 'form-status error';
|
||||
formStatus.textContent = 'Yhteysvirhe. Ota yhteyttä suoraan: box@storagebox.fi';
|
||||
}
|
||||
|
||||
submitBtn.textContent = originalText;
|
||||
submitBtn.disabled = false;
|
||||
|
||||
setTimeout(() => {
|
||||
formStatus.className = 'form-status';
|
||||
}, 5000);
|
||||
}, 8000);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user