Skip to content

Commit 0b6b775

Browse files
author
root
committed
fix: improve ContactForm configuration and validation for FormSubmit
- Convert ContactForm to Client Component with 'use client' - Use absolute URLs for redirect (required by FormSubmit) - Add acceptCharset='UTF-8' for proper character encoding - Add _template='table' for better email formatting - Improve honeypot field with proper styling and attributes - Add client-side form validation with user feedback - Add onSubmit handler to validate before sending to FormSubmit This should resolve the 'Form should POST' error by ensuring proper FormSubmit configuration.
1 parent e839f38 commit 0b6b775

1 file changed

Lines changed: 31 additions & 2 deletions

File tree

src/app/components/ContactForm/index.tsx

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,56 @@
1+
'use client';
2+
13
import React from 'react';
24

35
type Props = {
46
redirectPath?: string;
57
subject?: string;
68
};
79

10+
// Form validation function
11+
function validateForm(form: HTMLFormElement): boolean {
12+
const requiredFields = form.querySelectorAll('input[required], textarea[required]');
13+
for (const field of requiredFields) {
14+
const input = field as HTMLInputElement | HTMLTextAreaElement;
15+
if (!input.value.trim()) {
16+
alert(`Por favor, preencha o campo: ${input.previousElementSibling?.textContent || 'obrigatório'}`);
17+
input.focus();
18+
return false;
19+
}
20+
}
21+
return true;
22+
}
23+
824
export function ContactForm({
925
redirectPath = '/thanks',
1026
subject = 'Novo contato - Proposta | HelpDev',
1127
}: Props) {
1228
const actionUrl = 'https://formsubmit.co/gbzarelli@helpdev.com.br';
29+
const fullRedirectUrl = `https://helpdev.com.br${redirectPath}`;
30+
31+
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
32+
const form = e.currentTarget;
33+
if (!validateForm(form)) {
34+
e.preventDefault();
35+
return;
36+
}
37+
// Form is valid, let it submit normally to FormSubmit
38+
};
1339

1440
return (
1541
<form
1642
action={actionUrl}
1743
method="POST"
44+
acceptCharset="UTF-8"
45+
onSubmit={handleSubmit}
1846
className="bg-white text-gray-900 p-6 rounded-xl shadow-md max-w-2xl mx-auto text-left"
1947
>
2048
{/* FormSubmit configuration */}
21-
<input type="hidden" name="_next" value={redirectPath} />
49+
<input type="hidden" name="_next" value={fullRedirectUrl} />
2250
<input type="hidden" name="_subject" value={subject} />
2351
<input type="hidden" name="_captcha" value="false" />
24-
<input type="text" name="_honey" className="hidden" aria-hidden="true" />
52+
<input type="hidden" name="_template" value="table" />
53+
<input type="text" name="_honey" style={{display: 'none'}} tabIndex={-1} autoComplete="off" />
2554

2655
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
2756
<div>

0 commit comments

Comments
 (0)