diff --git a/src/app/components/ContactForm/index.tsx b/src/app/components/ContactForm/index.tsx index db92f99..02c2b9b 100644 --- a/src/app/components/ContactForm/index.tsx +++ b/src/app/components/ContactForm/index.tsx @@ -1,3 +1,5 @@ +'use client'; + import React from 'react'; type Props = { @@ -5,23 +7,50 @@ type Props = { subject?: string; }; +// Form validation function +function validateForm(form: HTMLFormElement): boolean { + const requiredFields = form.querySelectorAll('input[required], textarea[required]'); + for (const field of requiredFields) { + const input = field as HTMLInputElement | HTMLTextAreaElement; + if (!input.value.trim()) { + alert(`Por favor, preencha o campo: ${input.previousElementSibling?.textContent || 'obrigatório'}`); + input.focus(); + return false; + } + } + return true; +} + export function ContactForm({ redirectPath = '/thanks', subject = 'Novo contato - Proposta | HelpDev', }: Props) { const actionUrl = 'https://formsubmit.co/gbzarelli@helpdev.com.br'; + const fullRedirectUrl = `https://helpdev.com.br${redirectPath}`; + + const handleSubmit = (e: React.FormEvent) => { + const form = e.currentTarget; + if (!validateForm(form)) { + e.preventDefault(); + return; + } + // Form is valid, let it submit normally to FormSubmit + }; return (
{/* FormSubmit configuration */} - + - + +