diff options
| author | Danilo M. <danix@danix.xyz> | 2026-04-22 12:42:56 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-04-22 12:42:56 +0200 |
| commit | 631547a75142326a7c71bdf123e1475217a5ad73 (patch) | |
| tree | f3cfef6b3c5b42bf626fc823ddcf63b8dcf4cdbb /assets/js/contact-form.js | |
| parent | 77ccbe72fad5a4870185fff374f75471c16a9043 (diff) | |
| download | danixxyz-theme-631547a75142326a7c71bdf123e1475217a5ad73.tar.gz danixxyz-theme-631547a75142326a7c71bdf123e1475217a5ad73.zip | |
chore: replace with extracted danix.xyz-hacker theme (danix2-hugo-theme)
Diffstat (limited to 'assets/js/contact-form.js')
| -rw-r--r-- | assets/js/contact-form.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/assets/js/contact-form.js b/assets/js/contact-form.js new file mode 100644 index 0000000..4fa8f55 --- /dev/null +++ b/assets/js/contact-form.js @@ -0,0 +1,45 @@ +document.addEventListener('alpine:init', () => { + Alpine.data('contactForm', () => ({ + formData: { + name: '', + email: '', + message: '' + }, + isSubmitting: false, + statusMessage: '', + statusClass: '', + + async submitContactForm() { + this.isSubmitting = true; + this.statusMessage = ''; + this.statusClass = ''; + + try { + const response = await fetch('/contact.php', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(this.formData) + }); + + const data = await response.json(); + + if (response.ok) { + this.statusMessage = 'Message sent successfully!'; + this.statusClass = 'bg-green-100 text-green-800 border border-green-300'; + this.formData = { name: '', email: '', message: '' }; + } else { + this.statusMessage = data.error || 'An error occurred. Please try again.'; + this.statusClass = 'bg-red-100 text-red-800 border border-red-300'; + } + } catch (error) { + this.statusMessage = 'An error occurred. Please try again.'; + this.statusClass = 'bg-red-100 text-red-800 border border-red-300'; + console.error('Form submission error:', error); + } finally { + this.isSubmitting = false; + } + } + })); +}); |
