Next.js iletişim formu
Formgong team ·
Bunu Next.js içine yapıştırın. Başvurular Formgong’a gider. Veritabanı yok, Resend yok.
250 aylık ücretsiz başvuru
Next.js ile formlar nasıl çalışır
App Router'da bir formu işlemenin yerleşik yolu, genellikle gizli anahtarla bir e-posta API'sini çağıran bir Server Action veya route handler'dır. Bu bir sunucu ortamı gerektirir ve siteyi output: 'export' ile dışa aktardığınızda Server Actions desteklenmez.
https://formgong.com/submit adresine gönderen bir client component bunların hiçbirine ihtiyaç duymaz. Vercel'de, herhangi bir Node hosting'inde ve statik export olarak çalışır; her başvuru e-postaya ve Telegram'a gider, bir kopyası da Formgong gelen kutusunda kalır.
Next.js ile kurulum
- Formgong'da bir form oluşturun ve erişim anahtarını kopyalayın.
- Aşağıdaki bileşeni ekleyin. Bir tarayıcı olayını işlediği için
"use client"ile başlar. - Anahtarı değiştirin ya da
NEXT_PUBLIC_önekli bir değişkenden okuyun; tarayıcı koduna yalnızca bunlar ulaşır. - Bileşeni sayfanızda render edin,
next devçalıştırın ve bir deneme gönderin. - Paket mi tercih edersiniz?
@formgong/reacthazır bir<ContactForm>sunar; GitHub'daki Next.js starter ise eksiksiz bir projedir.
"use client";
import { useState } from "react";
export function ContactForm() {
const [status, setStatus] = useState("");
async function onSubmit(event) {
event.preventDefault();
const fields = Object.fromEntries(new FormData(event.currentTarget));
const response = await fetch("https://formgong.com/submit", {
method: "POST",
headers: { "Content-Type": "application/json", Accept: "application/json" },
body: JSON.stringify({ _lang: "en", ...fields, access_key: "fk_your_access_key" }),
});
const result = await response.json();
setStatus(result.message || (result.success ? "Sent. Thank you!" : "Could not send. Please try again."));
}
return (
<form onSubmit={onSubmit}>
<label>Name <input name="name" placeholder="Your name" required /></label>
<label>Email <input name="email" type="email" placeholder="you@example.com" required /></label>
<label>Message <textarea name="message" placeholder="How can we help?" required /></label>
<div aria-hidden="true" style={{ position: "absolute", insetInlineStart: 0, top: 0, width: 1, height: 1, overflow: "hidden", clipPath: "inset(50%)" }}>
<input name="botcheck" tabIndex={-1} autoComplete="off" />
</div>
<button type="submit">Send</button>
<p role="status">{status}</p>
</form>
);
}"use client";
import { useState } from "react";
export function ContactForm() {
const [status, setStatus] = useState("");
async function onSubmit(event) {
event.preventDefault();
const fields = Object.fromEntries(new FormData(event.currentTarget));
const response = await fetch("https://formgong.com/submit", {
method: "POST",
headers: { "Content-Type": "application/json", Accept: "application/json" },
body: JSON.stringify({ _lang: "uk", ...fields, access_key: "fk_your_access_key" }),
});
const result = await response.json();
setStatus(result.message || (result.success ? "Надіслано. Дякуємо!" : "Не вдалося надіслати. Спробуйте ще раз."));
}
return (
<form onSubmit={onSubmit}>
<label>Ім’я <input name="name" placeholder="Ваше ім’я" required /></label>
<label>Email <input name="email" type="email" placeholder="you@example.com" required /></label>
<label>Повідомлення <textarea name="message" placeholder="Чим ми можемо допомогти?" required /></label>
<div aria-hidden="true" style={{ position: "absolute", insetInlineStart: 0, top: 0, width: 1, height: 1, overflow: "hidden", clipPath: "inset(50%)" }}>
<input name="botcheck" tabIndex={-1} autoComplete="off" />
</div>
<button type="submit">Надіслати</button>
<p role="status">{status}</p>
</form>
);
}"use client";
import { useState } from "react";
export function ContactForm() {
const [status, setStatus] = useState("");
async function onSubmit(event) {
event.preventDefault();
const fields = Object.fromEntries(new FormData(event.currentTarget));
const response = await fetch("https://formgong.com/submit", {
method: "POST",
headers: { "Content-Type": "application/json", Accept: "application/json" },
body: JSON.stringify({ _lang: "pl", ...fields, access_key: "fk_your_access_key" }),
});
const result = await response.json();
setStatus(result.message || (result.success ? "Wysłano. Dziękujemy!" : "Nie udało się wysłać. Spróbuj ponownie."));
}
return (
<form onSubmit={onSubmit}>
<label>Imię <input name="name" placeholder="Twoje imię" required /></label>
<label>E-mail <input name="email" type="email" placeholder="ty@example.com" required /></label>
<label>Wiadomość <textarea name="message" placeholder="W czym możemy pomóc?" required /></label>
<div aria-hidden="true" style={{ position: "absolute", insetInlineStart: 0, top: 0, width: 1, height: 1, overflow: "hidden", clipPath: "inset(50%)" }}>
<input name="botcheck" tabIndex={-1} autoComplete="off" />
</div>
<button type="submit">Wyślij</button>
<p role="status">{status}</p>
</form>
);
}"use client";
import { useState } from "react";
export function ContactForm() {
const [status, setStatus] = useState("");
async function onSubmit(event) {
event.preventDefault();
const fields = Object.fromEntries(new FormData(event.currentTarget));
const response = await fetch("https://formgong.com/submit", {
method: "POST",
headers: { "Content-Type": "application/json", Accept: "application/json" },
body: JSON.stringify({ _lang: "tr", ...fields, access_key: "fk_your_access_key" }),
});
const result = await response.json();
setStatus(result.message || (result.success ? "Gönderildi. Teşekkürler!" : "Gönderilemedi. Lütfen tekrar deneyin."));
}
return (
<form onSubmit={onSubmit}>
<label>Ad <input name="name" placeholder="Adınız" required /></label>
<label>E-posta <input name="email" type="email" placeholder="siz@ornek.com" required /></label>
<label>Mesaj <textarea name="message" placeholder="Size nasıl yardımcı olabiliriz?" required /></label>
<div aria-hidden="true" style={{ position: "absolute", insetInlineStart: 0, top: 0, width: 1, height: 1, overflow: "hidden", clipPath: "inset(50%)" }}>
<input name="botcheck" tabIndex={-1} autoComplete="off" />
</div>
<button type="submit">Gönder</button>
<p role="status">{status}</p>
</form>
);
}"use client";
import { useState } from "react";
export function ContactForm() {
const [status, setStatus] = useState("");
async function onSubmit(event) {
event.preventDefault();
const fields = Object.fromEntries(new FormData(event.currentTarget));
const response = await fetch("https://formgong.com/submit", {
method: "POST",
headers: { "Content-Type": "application/json", Accept: "application/json" },
body: JSON.stringify({ _lang: "es", ...fields, access_key: "fk_your_access_key" }),
});
const result = await response.json();
setStatus(result.message || (result.success ? "Enviado. ¡Gracias!" : "No se pudo enviar. Inténtalo de nuevo."));
}
return (
<form onSubmit={onSubmit}>
<label>Nombre <input name="name" placeholder="Tu nombre" required /></label>
<label>Correo electrónico <input name="email" type="email" placeholder="tu@ejemplo.com" required /></label>
<label>Mensaje <textarea name="message" placeholder="¿En qué podemos ayudarte?" required /></label>
<div aria-hidden="true" style={{ position: "absolute", insetInlineStart: 0, top: 0, width: 1, height: 1, overflow: "hidden", clipPath: "inset(50%)" }}>
<input name="botcheck" tabIndex={-1} autoComplete="off" />
</div>
<button type="submit">Enviar</button>
<p role="status">{status}</p>
</form>
);
}"use client";
import { useState } from "react";
export function ContactForm() {
const [status, setStatus] = useState("");
async function onSubmit(event) {
event.preventDefault();
const fields = Object.fromEntries(new FormData(event.currentTarget));
const response = await fetch("https://formgong.com/submit", {
method: "POST",
headers: { "Content-Type": "application/json", Accept: "application/json" },
body: JSON.stringify({ _lang: "fr", ...fields, access_key: "fk_your_access_key" }),
});
const result = await response.json();
setStatus(result.message || (result.success ? "Envoyé. Merci !" : "Échec de l’envoi. Veuillez réessayer."));
}
return (
<form onSubmit={onSubmit}>
<label>Nom <input name="name" placeholder="Votre nom" required /></label>
<label>E-mail <input name="email" type="email" placeholder="vous@exemple.com" required /></label>
<label>Message <textarea name="message" placeholder="Comment pouvons-nous vous aider ?" required /></label>
<div aria-hidden="true" style={{ position: "absolute", insetInlineStart: 0, top: 0, width: 1, height: 1, overflow: "hidden", clipPath: "inset(50%)" }}>
<input name="botcheck" tabIndex={-1} autoComplete="off" />
</div>
<button type="submit">Envoyer</button>
<p role="status">{status}</p>
</form>
);
}"use client";
import { useState } from "react";
export function ContactForm() {
const [status, setStatus] = useState("");
async function onSubmit(event) {
event.preventDefault();
const fields = Object.fromEntries(new FormData(event.currentTarget));
const response = await fetch("https://formgong.com/submit", {
method: "POST",
headers: { "Content-Type": "application/json", Accept: "application/json" },
body: JSON.stringify({ _lang: "pt", ...fields, access_key: "fk_your_access_key" }),
});
const result = await response.json();
setStatus(result.message || (result.success ? "Enviado. Obrigado!" : "Não foi possível enviar. Tente novamente."));
}
return (
<form onSubmit={onSubmit}>
<label>Nome <input name="name" placeholder="O seu nome" required /></label>
<label>E-mail <input name="email" type="email" placeholder="voce@exemplo.com" required /></label>
<label>Mensagem <textarea name="message" placeholder="Como podemos ajudar?" required /></label>
<div aria-hidden="true" style={{ position: "absolute", insetInlineStart: 0, top: 0, width: 1, height: 1, overflow: "hidden", clipPath: "inset(50%)" }}>
<input name="botcheck" tabIndex={-1} autoComplete="off" />
</div>
<button type="submit">Enviar</button>
<p role="status">{status}</p>
</form>
);
}"use client";
import { useState } from "react";
export function ContactForm() {
const [status, setStatus] = useState("");
async function onSubmit(event) {
event.preventDefault();
const fields = Object.fromEntries(new FormData(event.currentTarget));
const response = await fetch("https://formgong.com/submit", {
method: "POST",
headers: { "Content-Type": "application/json", Accept: "application/json" },
body: JSON.stringify({ _lang: "ar", ...fields, access_key: "fk_your_access_key" }),
});
const result = await response.json();
setStatus(result.message || (result.success ? "تم الإرسال. شكرًا لك!" : "تعذّر الإرسال. يرجى المحاولة مرة أخرى."));
}
return (
<form onSubmit={onSubmit}>
<label>الاسم <input name="name" placeholder="اسمك" required /></label>
<label>البريد الإلكتروني <input name="email" type="email" placeholder="you@example.com" required /></label>
<label>الرسالة <textarea name="message" placeholder="كيف يمكننا مساعدتك؟" required /></label>
<div aria-hidden="true" style={{ position: "absolute", insetInlineStart: 0, top: 0, width: 1, height: 1, overflow: "hidden", clipPath: "inset(50%)" }}>
<input name="botcheck" tabIndex={-1} autoComplete="off" />
</div>
<button type="submit">إرسال</button>
<p role="status">{status}</p>
</form>
);
}"use client";
import { useState } from "react";
export function ContactForm() {
const [status, setStatus] = useState("");
async function onSubmit(event) {
event.preventDefault();
const fields = Object.fromEntries(new FormData(event.currentTarget));
const response = await fetch("https://formgong.com/submit", {
method: "POST",
headers: { "Content-Type": "application/json", Accept: "application/json" },
body: JSON.stringify({ _lang: "he", ...fields, access_key: "fk_your_access_key" }),
});
const result = await response.json();
setStatus(result.message || (result.success ? "נשלח. תודה!" : "השליחה נכשלה. נא לנסות שוב."));
}
return (
<form onSubmit={onSubmit}>
<label>שם <input name="name" placeholder="השם שלך" required /></label>
<label>אימייל <input name="email" type="email" placeholder="you@example.com" required /></label>
<label>הודעה <textarea name="message" placeholder="איך נוכל לעזור?" required /></label>
<div aria-hidden="true" style={{ position: "absolute", insetInlineStart: 0, top: 0, width: 1, height: 1, overflow: "hidden", clipPath: "inset(50%)" }}>
<input name="botcheck" tabIndex={-1} autoComplete="off" />
</div>
<button type="submit">שליחה</button>
<p role="status">{status}</p>
</form>
);
}"use client";
import { useState } from "react";
export function ContactForm() {
const [status, setStatus] = useState("");
async function onSubmit(event) {
event.preventDefault();
const fields = Object.fromEntries(new FormData(event.currentTarget));
const response = await fetch("https://formgong.com/submit", {
method: "POST",
headers: { "Content-Type": "application/json", Accept: "application/json" },
body: JSON.stringify({ _lang: "hi", ...fields, access_key: "fk_your_access_key" }),
});
const result = await response.json();
setStatus(result.message || (result.success ? "भेज दिया गया। धन्यवाद!" : "भेजा नहीं जा सका। कृपया फिर से कोशिश करें।"));
}
return (
<form onSubmit={onSubmit}>
<label>नाम <input name="name" placeholder="आपका नाम" required /></label>
<label>ईमेल <input name="email" type="email" placeholder="you@example.com" required /></label>
<label>संदेश <textarea name="message" placeholder="हम आपकी कैसे मदद कर सकते हैं?" required /></label>
<div aria-hidden="true" style={{ position: "absolute", insetInlineStart: 0, top: 0, width: 1, height: 1, overflow: "hidden", clipPath: "inset(50%)" }}>
<input name="botcheck" tabIndex={-1} autoComplete="off" />
</div>
<button type="submit">भेजें</button>
<p role="status">{status}</p>
</form>
);
}"use client";
import { useState } from "react";
export function ContactForm() {
const [status, setStatus] = useState("");
async function onSubmit(event) {
event.preventDefault();
const fields = Object.fromEntries(new FormData(event.currentTarget));
const response = await fetch("https://formgong.com/submit", {
method: "POST",
headers: { "Content-Type": "application/json", Accept: "application/json" },
body: JSON.stringify({ _lang: "ja", ...fields, access_key: "fk_your_access_key" }),
});
const result = await response.json();
setStatus(result.message || (result.success ? "送信しました。ありがとうございます。" : "送信できませんでした。もう一度お試しください。"));
}
return (
<form onSubmit={onSubmit}>
<label>お名前 <input name="name" placeholder="山田 太郎" required /></label>
<label>メールアドレス <input name="email" type="email" placeholder="you@example.com" required /></label>
<label>メッセージ <textarea name="message" placeholder="ご用件をご記入ください" required /></label>
<div aria-hidden="true" style={{ position: "absolute", insetInlineStart: 0, top: 0, width: 1, height: 1, overflow: "hidden", clipPath: "inset(50%)" }}>
<input name="botcheck" tabIndex={-1} autoComplete="off" />
</div>
<button type="submit">送信</button>
<p role="status">{status}</p>
</form>
);
}"use client";
import { useState } from "react";
export function ContactForm() {
const [status, setStatus] = useState("");
async function onSubmit(event) {
event.preventDefault();
const fields = Object.fromEntries(new FormData(event.currentTarget));
const response = await fetch("https://formgong.com/submit", {
method: "POST",
headers: { "Content-Type": "application/json", Accept: "application/json" },
body: JSON.stringify({ _lang: "de", ...fields, access_key: "fk_your_access_key" }),
});
const result = await response.json();
setStatus(result.message || (result.success ? "Gesendet. Vielen Dank!" : "Das Senden ist fehlgeschlagen. Bitte versuchen Sie es erneut."));
}
return (
<form onSubmit={onSubmit}>
<label>Name <input name="name" placeholder="Ihr Name" required /></label>
<label>E-Mail <input name="email" type="email" placeholder="name@beispiel.de" required /></label>
<label>Nachricht <textarea name="message" placeholder="Wie können wir Ihnen helfen?" required /></label>
<div aria-hidden="true" style={{ position: "absolute", insetInlineStart: 0, top: 0, width: 1, height: 1, overflow: "hidden", clipPath: "inset(50%)" }}>
<input name="botcheck" tabIndex={-1} autoComplete="off" />
</div>
<button type="submit">Senden</button>
<p role="status">{status}</p>
</form>
);
}GitHub'da hazır başlangıç şablonu: github.com/formgong/nextjs-starter. MIT lisansı: “Use this template” düğmesine tıklayın veya dosyaları kopyalayın.
Tek komutla yeni proje: npm create formgong@latest -- --template nextjs (npm: create-formgong)
Bileşen paketi: npm install @formgong/next (npm: @formgong/next)
Mevcut projeye ekleyin: npx formgong init (npm: formgong)
Formgong mu, Server Action mı?
Gönderim verilerinizi değiştirecek veya giriş yapmış bir kullanıcıyı kontrol edecekse bir Server Action yazın.
İletişim, teklif ve başvuru formları için Formgong'u kullanın: kod tabanınızda e-posta sağlayıcısı, gizli anahtar ve spam yönetimi olmaz.
Sorular ve yanıtlar
Anahtarı gizlemek için isteği bir Server Action üzerinden geçirebilir miyim?
Geçirebilirsiniz, ama gizlenecek bir şey yok: anahtar herkese açıktır. Proxy ayrıca her gönderimin sunucunuzun IP'sinden gelmesine yol açar; bu da hız sınırlarını ve spam sinyallerini zayıflatır.
Statik export ile çalışır mı?
Evet. Formgong'a gönderen bir client component sunucu gerektirmez; Server Actions ise statik export'ta desteklenmez.
Pages Router mı, App Router mı?
İkisi de. Pages Router'da "use client" satırını kaldırın; gerisi aynıdır.
Resend veya bir Server Action gerekir mi?
İletişim formu için hayır. Resend doğrulanmış bir alan adı ve DNS kayıtları ister. API anahtarı sunucuda kalır. Gönderim veritabanınızı değiştirecek veya oturum açmış kullanıcıyı kontrol edecekse bir Server Action yazın.
Next.js formunda spam nasıl durdurulur?
botcheck alanını boş bırakın. Formgong dolu bir honeypot'u spam sayar ve bunu e-postayla veya Telegram ile göndermez. Turnstile isteğe bağlıdır. Widget'ı yalnızca form ayarlarında açtıktan sonra ekleyin. Gizli anahtar Formgong'da kalır.