diff --git a/src/components/ContactForm.vue b/src/components/ContactForm.vue index 86ba99f..3d88100 100644 --- a/src/components/ContactForm.vue +++ b/src/components/ContactForm.vue @@ -26,7 +26,7 @@ onMounted(() => { script.async = true; script.defer = true; document.head.appendChild(script); - + // Initialize Turnstile once the script is loaded script.onload = () => { if (window.turnstile) { @@ -39,10 +39,24 @@ onMounted(() => { responseMessage.value = "Turnstile validation failed. Please try again."; }, }); - } + }; + }; }); +// Phone number formatting logic +function formatPhoneNumber(value: string): string { + const cleaned = value.replace(/\D/g, ''); // Remove non-digit characters + const match = cleaned.match(/(\d{0,3})(\d{0,3})(\d{0,4})/); + if (!match) return ''; + return !match[2] ? match[1] : `${match[1]}-${match[2]}${match[3] ? '-' + match[3] : ''}`; +}; + +function handlePhoneInput(event: Event) { + const input = event.target as HTMLInputElement; + formData.value.phone = formatPhoneNumber(input.value); +}; + // Set character limits const nameMaxLength = 100; const emailMaxLength = 150; @@ -57,11 +71,11 @@ async function submit(e: Event) { if (!formData.value.turnstileToken) { responseMessage.value = "Please complete the Turnstile challenge."; return; - } + }; if (isSubmitting.value) { return; - } + }; isSubmitting.value = true; responseMessage.value = ''; // Clear previous response message @@ -89,7 +103,7 @@ async function submit(e: Event) { if (response.ok) { responseMessage.value = "Message sent successfully!"; - // resetForm(); + resetForm(); } else { responseMessage.value = `Error: ${data.message || "Something went wrong"}`; } @@ -97,8 +111,8 @@ async function submit(e: Event) { responseMessage.value = 'An error occurred. Please try again later.'; } finally { isSubmitting.value = false; - } -} + }; +}; // Reset form data function resetForm() { @@ -112,7 +126,7 @@ function resetForm() { turnstileToken: '' }; responseMessage.value = ''; -} +}; @@ -122,43 +136,114 @@ function resetForm() {
- +
- +
- - -
+
+ + + + + + +
+
+ +
+
- +
- +
- +