Angular iletişim formu
Formgong team ·
Bunu Angular içine yapıştırın. Başvurular Formgong’a gider. Veritabanı yok, Resend yok.
250 aylık ücretsiz başvuru
Angular ile formlar nasıl çalışır
Bir Angular uygulaması tarayıcıda çalışır, bu yüzden iletişim formu e-posta göndermek için genellikle kendi backend'ine ihtiyaç duyar. Formgong bu rolü üstlenir: bileşen alanları https://formgong.com/submit adresine gönderir ve çevrilmiş yanıtı gösterir.
Kod, (ngSubmit) olayını işleyen bir standalone component'tir. Tarayıcının fetch işlevini kullandığı için HttpClient kurulumu gerektirmez. Uygulamanız provideHttpClient() ile zaten HttpClient sağlıyorsa aynı isteği onunla da gönderebilirsiniz.
Angular ile kurulum
- Formgong'da bir form oluşturun ve erişim anahtarını kopyalayın.
- Aşağıdaki bileşeni ekleyin ve anahtarı değiştirin.
(ngSubmit)tetiklensin ve sayfa yenilenmesin diye bileşendeFormsModuleiçe aktarın. - Reactive Forms kullanıyorsanız
FormGroupyapınızı koruyun ve değerini gönderim işleyicisinde gönderin. ng serveçalıştırın, bir deneme gönderin ve Formgong gelen kutusunu kontrol edin.
import { Component } from "@angular/core";
@Component({
selector: "contact-form",
template: `
<form (ngSubmit)="onSubmit($event)">
<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></textarea></label>
<div aria-hidden="true" style="position:absolute;inset-inline-start:0;top:0;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)">
<input name="botcheck" tabindex="-1" autocomplete="off">
</div>
<button type="submit">Send</button>
<p role="status">{{ status }}</p>
</form>
`,
})
export class ContactForm {
status = "";
async onSubmit(event: Event) {
event.preventDefault();
const form = event.currentTarget;
if (!(form instanceof HTMLFormElement)) return;
const fields = Object.fromEntries(new FormData(form));
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();
this.status = result.message || (result.success ? "Sent. Thank you!" : "Could not send. Please try again.");
}
}import { Component } from "@angular/core";
@Component({
selector: "contact-form",
template: `
<form (ngSubmit)="onSubmit($event)">
<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></textarea></label>
<div aria-hidden="true" style="position:absolute;inset-inline-start:0;top:0;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)">
<input name="botcheck" tabindex="-1" autocomplete="off">
</div>
<button type="submit">Надіслати</button>
<p role="status">{{ status }}</p>
</form>
`,
})
export class ContactForm {
status = "";
async onSubmit(event: Event) {
event.preventDefault();
const form = event.currentTarget;
if (!(form instanceof HTMLFormElement)) return;
const fields = Object.fromEntries(new FormData(form));
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();
this.status = result.message || (result.success ? "Надіслано. Дякуємо!" : "Не вдалося надіслати. Спробуйте ще раз.");
}
}import { Component } from "@angular/core";
@Component({
selector: "contact-form",
template: `
<form (ngSubmit)="onSubmit($event)">
<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></textarea></label>
<div aria-hidden="true" style="position:absolute;inset-inline-start:0;top:0;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)">
<input name="botcheck" tabindex="-1" autocomplete="off">
</div>
<button type="submit">Wyślij</button>
<p role="status">{{ status }}</p>
</form>
`,
})
export class ContactForm {
status = "";
async onSubmit(event: Event) {
event.preventDefault();
const form = event.currentTarget;
if (!(form instanceof HTMLFormElement)) return;
const fields = Object.fromEntries(new FormData(form));
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();
this.status = result.message || (result.success ? "Wysłano. Dziękujemy!" : "Nie udało się wysłać. Spróbuj ponownie.");
}
}import { Component } from "@angular/core";
@Component({
selector: "contact-form",
template: `
<form (ngSubmit)="onSubmit($event)">
<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></textarea></label>
<div aria-hidden="true" style="position:absolute;inset-inline-start:0;top:0;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)">
<input name="botcheck" tabindex="-1" autocomplete="off">
</div>
<button type="submit">Gönder</button>
<p role="status">{{ status }}</p>
</form>
`,
})
export class ContactForm {
status = "";
async onSubmit(event: Event) {
event.preventDefault();
const form = event.currentTarget;
if (!(form instanceof HTMLFormElement)) return;
const fields = Object.fromEntries(new FormData(form));
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();
this.status = result.message || (result.success ? "Gönderildi. Teşekkürler!" : "Gönderilemedi. Lütfen tekrar deneyin.");
}
}import { Component } from "@angular/core";
@Component({
selector: "contact-form",
template: `
<form (ngSubmit)="onSubmit($event)">
<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></textarea></label>
<div aria-hidden="true" style="position:absolute;inset-inline-start:0;top:0;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)">
<input name="botcheck" tabindex="-1" autocomplete="off">
</div>
<button type="submit">Enviar</button>
<p role="status">{{ status }}</p>
</form>
`,
})
export class ContactForm {
status = "";
async onSubmit(event: Event) {
event.preventDefault();
const form = event.currentTarget;
if (!(form instanceof HTMLFormElement)) return;
const fields = Object.fromEntries(new FormData(form));
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();
this.status = result.message || (result.success ? "Enviado. ¡Gracias!" : "No se pudo enviar. Inténtalo de nuevo.");
}
}import { Component } from "@angular/core";
@Component({
selector: "contact-form",
template: `
<form (ngSubmit)="onSubmit($event)">
<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></textarea></label>
<div aria-hidden="true" style="position:absolute;inset-inline-start:0;top:0;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)">
<input name="botcheck" tabindex="-1" autocomplete="off">
</div>
<button type="submit">Envoyer</button>
<p role="status">{{ status }}</p>
</form>
`,
})
export class ContactForm {
status = "";
async onSubmit(event: Event) {
event.preventDefault();
const form = event.currentTarget;
if (!(form instanceof HTMLFormElement)) return;
const fields = Object.fromEntries(new FormData(form));
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();
this.status = result.message || (result.success ? "Envoyé. Merci !" : "Échec de l’envoi. Veuillez réessayer.");
}
}import { Component } from "@angular/core";
@Component({
selector: "contact-form",
template: `
<form (ngSubmit)="onSubmit($event)">
<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></textarea></label>
<div aria-hidden="true" style="position:absolute;inset-inline-start:0;top:0;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)">
<input name="botcheck" tabindex="-1" autocomplete="off">
</div>
<button type="submit">Enviar</button>
<p role="status">{{ status }}</p>
</form>
`,
})
export class ContactForm {
status = "";
async onSubmit(event: Event) {
event.preventDefault();
const form = event.currentTarget;
if (!(form instanceof HTMLFormElement)) return;
const fields = Object.fromEntries(new FormData(form));
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();
this.status = result.message || (result.success ? "Enviado. Obrigado!" : "Não foi possível enviar. Tente novamente.");
}
}import { Component } from "@angular/core";
@Component({
selector: "contact-form",
template: `
<form (ngSubmit)="onSubmit($event)">
<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></textarea></label>
<div aria-hidden="true" style="position:absolute;inset-inline-start:0;top:0;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)">
<input name="botcheck" tabindex="-1" autocomplete="off">
</div>
<button type="submit">إرسال</button>
<p role="status">{{ status }}</p>
</form>
`,
})
export class ContactForm {
status = "";
async onSubmit(event: Event) {
event.preventDefault();
const form = event.currentTarget;
if (!(form instanceof HTMLFormElement)) return;
const fields = Object.fromEntries(new FormData(form));
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();
this.status = result.message || (result.success ? "تم الإرسال. شكرًا لك!" : "تعذّر الإرسال. يرجى المحاولة مرة أخرى.");
}
}import { Component } from "@angular/core";
@Component({
selector: "contact-form",
template: `
<form (ngSubmit)="onSubmit($event)">
<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></textarea></label>
<div aria-hidden="true" style="position:absolute;inset-inline-start:0;top:0;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)">
<input name="botcheck" tabindex="-1" autocomplete="off">
</div>
<button type="submit">שליחה</button>
<p role="status">{{ status }}</p>
</form>
`,
})
export class ContactForm {
status = "";
async onSubmit(event: Event) {
event.preventDefault();
const form = event.currentTarget;
if (!(form instanceof HTMLFormElement)) return;
const fields = Object.fromEntries(new FormData(form));
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();
this.status = result.message || (result.success ? "נשלח. תודה!" : "השליחה נכשלה. נא לנסות שוב.");
}
}import { Component } from "@angular/core";
@Component({
selector: "contact-form",
template: `
<form (ngSubmit)="onSubmit($event)">
<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></textarea></label>
<div aria-hidden="true" style="position:absolute;inset-inline-start:0;top:0;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)">
<input name="botcheck" tabindex="-1" autocomplete="off">
</div>
<button type="submit">भेजें</button>
<p role="status">{{ status }}</p>
</form>
`,
})
export class ContactForm {
status = "";
async onSubmit(event: Event) {
event.preventDefault();
const form = event.currentTarget;
if (!(form instanceof HTMLFormElement)) return;
const fields = Object.fromEntries(new FormData(form));
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();
this.status = result.message || (result.success ? "भेज दिया गया। धन्यवाद!" : "भेजा नहीं जा सका। कृपया फिर से कोशिश करें।");
}
}import { Component } from "@angular/core";
@Component({
selector: "contact-form",
template: `
<form (ngSubmit)="onSubmit($event)">
<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></textarea></label>
<div aria-hidden="true" style="position:absolute;inset-inline-start:0;top:0;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)">
<input name="botcheck" tabindex="-1" autocomplete="off">
</div>
<button type="submit">送信</button>
<p role="status">{{ status }}</p>
</form>
`,
})
export class ContactForm {
status = "";
async onSubmit(event: Event) {
event.preventDefault();
const form = event.currentTarget;
if (!(form instanceof HTMLFormElement)) return;
const fields = Object.fromEntries(new FormData(form));
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();
this.status = result.message || (result.success ? "送信しました。ありがとうございます。" : "送信できませんでした。もう一度お試しください。");
}
}import { Component } from "@angular/core";
@Component({
selector: "contact-form",
template: `
<form (ngSubmit)="onSubmit($event)">
<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></textarea></label>
<div aria-hidden="true" style="position:absolute;inset-inline-start:0;top:0;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)">
<input name="botcheck" tabindex="-1" autocomplete="off">
</div>
<button type="submit">Senden</button>
<p role="status">{{ status }}</p>
</form>
`,
})
export class ContactForm {
status = "";
async onSubmit(event: Event) {
event.preventDefault();
const form = event.currentTarget;
if (!(form instanceof HTMLFormElement)) return;
const fields = Object.fromEntries(new FormData(form));
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();
this.status = result.message || (result.success ? "Gesendet. Vielen Dank!" : "Das Senden ist fehlgeschlagen. Bitte versuchen Sie es erneut.");
}
}Bileşen paketi: npm install @formgong/angular (npm: @formgong/angular)
Mevcut projeye ekleyin: npx formgong init (npm: formgong)
Formgong mu, kendi backend'iniz mi?
Form sisteminizdeki verileri değiştiriyorsa doğru yer kendi backend'inizdir.
İletişim ve başvuru formlarında Formgong, backend'i, e-posta sağlayıcısını ve spam filtrelemeyi projenizden çıkarır.
Sorular ve yanıtlar
fetch mi, HttpClient mı?
İkisi de çalışır. fetch kurulum gerektirmez; interceptor'lar kullanıyorsanız veya observable istiyorsanız HttpClient uygundur.
Gönderdiğimde sayfa neden yenileniyor?
Genellikle FormsModule içe aktarılmamıştır, bu yüzden (ngSubmit) çalışmaz ve formu tarayıcı kendisi gönderir. Modülü içe aktarın ya da event.preventDefault() çağırın.
Angular SSR ile çalışır mı?
Evet. İstek yalnızca ziyaretçi formu tarayıcıda gönderdiğinde çalışır.