Angular Contact Form Integration (Standalone & Signals)
Connect Angular 17/18+ applications to Lugatu using Standalone Components, reactive Signals, and HttpClient for reliable contact form delivery without maintaining an SMTP server.
1. Standalone Contact Form Component with Reactive Signals
Modern Angular favors Standalone Components and Signals over heavy NgModules. This implementation provides an accessible contact form with reactive loading, error, and success states submitting directly to Lugatu.
import { Component, signal, inject } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { HttpClient } from '@angular/common/http';
@Component({
selector: 'app-contact-form',
standalone: true,
imports: [CommonModule, FormsModule],
template: `
<form (ngSubmit)="onSubmit()" class="space-y-4 max-w-md">
<div>
<label for="name" class="block text-sm font-semibold mb-1">Your Name</label>
<input id="name" type="text" [(ngModel)]="name" name="name" required class="w-full border rounded-xl p-2.5" />
</div>
<div>
<label for="email" class="block text-sm font-semibold mb-1">Email Address</label>
<input id="email" type="email" [(ngModel)]="email" name="email" required class="w-full border rounded-xl p-2.5" />
</div>
<div>
<label for="message" class="block text-sm font-semibold mb-1">Message</label>
<textarea id="message" rows="4" [(ngModel)]="message" name="message" required class="w-full border rounded-xl p-2.5"></textarea>
</div>
<!-- Honeypot spam defense -->
<input type="text" [(ngModel)]="gotcha" name="_gotcha" style="display:none !important" tabindex="-1" autocomplete="off" />
<button type="submit" [disabled]="isSubmitting()" class="btn-primary-editorial py-2.5 px-6">
{{ isSubmitting() ? 'Sending...' : 'Send Message' }}
</button>
<p *ngIf="isSuccess()" class="text-sm text-green-700 font-medium">Thank you! Your message has been received.</p>
<p *ngIf="errorMessage()" class="text-sm text-red-600">{{ errorMessage() }}</p>
</form>
`,
})
export class ContactFormComponent {
private http = inject(HttpClient);
name = signal('');
email = signal('');
message = signal('');
gotcha = signal('');
isSubmitting = signal(false);
isSuccess = signal(false);
errorMessage = signal('');
onSubmit() {
if (this.gotcha()) return; // Silent discard for automated bot submissions
this.isSubmitting.set(true);
this.errorMessage.set('');
const payload = {
fields: {
name: this.name(),
email: this.email(),
message: this.message(),
},
honeypot: this.gotcha(),
};
this.http.post('https://www.lugatu.com/api/v1/public/forms/YOUR_PUBLIC_FORM_ID/submissions', payload)
.subscribe({
next: () => {
this.isSubmitting.set(false);
this.isSuccess.set(true);
this.name.set('');
this.email.set('');
this.message.set('');
},
error: () => {
this.isSubmitting.set(false);
this.errorMessage.set('Submission failed. Please try again.');
},
});
}
}
2. SSR & Angular Universal Server-to-Server Forwarding
If your Angular application runs with Angular SSR (Node / Express engine), you can proxy inquiries through a server-side route handler to protect your Lugatu Server-to-Server API key.
// Express / Node backend endpoint in Angular SSR
server.post('/api/contact', async (req, res) => {
const { name, email, message, _gotcha } = req.body;
if (_gotcha) return res.status(200).json({ ok: true });
try {
const response = await fetch(`https://www.lugatu.com/api/v1/forms/${process.env.LUGATU_FORM_ID}/submissions`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.LUGATU_API_KEY}`,
'Content-Type': 'application/json',
'Idempotency-Key': crypto.randomUUID(),
},
body: JSON.stringify({ fields: { name, email, message } }),
});
res.status(response.status).json({ ok: response.ok });
} catch (error) {
res.status(500).json({ error: 'Failed to deliver message' });
}
});
3. Bot Defense & Honeypot Configuration
Lugatu inspects the _gotcha field automatically. Keep it invisible to human visitors using display:none and tabindex="-1". Spambots filling every DOM input trigger silent suppression.
Never use form labels for honeypot inputs. Leave autocomplete off and exclude the field from screen-reader accessible names.
Security & Authentication Invariant
Security Invariant: Server-to-server API keys (lug_live_...) must never be bundled into client-side Angular assets or environment.ts files. Use the public endpoint for direct client submissions or forward via server endpoints.
Troubleshooting & Common Ingestion Errors
Public form endpoints permit cross-origin submissions from any browser. If you are calling the server-to-server endpoint (POST /api/v1/forms/{id}/submissions) directly from Angular, switch to the public endpoint (POST /api/v1/public/forms/{id}/submissions) or forward through a backend.
Frequently Asked Questions
Does Lugatu support Angular SSR with client hydration?
Yes. Lugatu public form submissions are performed via client-side fetch or HttpClient after user interaction, which is completely compatible with Angular SSR and client hydration.
Ready to create your form endpoint?
Get started for free in seconds. No credit card required.