Frameworks and builders
Remix
Add a Lazyform contact form to Remix or React Router v7, posting from the browser or through a route action.
Remix is now React Router v7 (framework mode). The examples below use React Router v7 imports; on Remix v2, import the same hooks from @remix-run/react instead. You can post straight from the browser, or use a route action that posts from your server.
Before you start
Get an access key: type your email on the homepage for an instant key, or sign in and create a form. Replace YOUR_ACCESS_KEY with your key (it starts with lf_).
The minimal form
A plain <form> (not Remix's <Form>) posts directly to Lazyform and shows a thank-you page.
export default function Contact() {
return (
<form action="https://lazyform-api.xvelopers.com/submit" method="post">
<input type="hidden" name="access_key" value="YOUR_ACCESS_KEY" />
<input type="text" name="name" placeholder="Name" required />
<input type="email" name="email" placeholder="Email" required />
<textarea name="message" placeholder="Message" required />
<input type="checkbox" name="botcheck" className="hidden" style={{ display: 'none' }} tabIndex={-1} autoComplete="off" />
<button type="submit">Send</button>
</form>
);
}From the browser or through an action
// app/routes/contact.tsx
import { useState, type FormEvent } from 'react';
export default function Contact() {
const [status, setStatus] = useState<'idle' | 'sending' | 'success' | 'error'>('idle');
const [error, setError] = useState('');
async function handleSubmit(event: FormEvent<HTMLFormElement>) {
event.preventDefault();
const form = event.currentTarget;
setStatus('sending');
try {
const response = await fetch('https://lazyform-api.xvelopers.com/submit', {
method: 'POST',
headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
body: JSON.stringify(Object.fromEntries(new FormData(form))),
});
const result = await response.json();
if (result.success) {
setStatus('success');
} else {
setStatus('error');
setError(result.error?.message ?? 'Something went wrong.');
}
} catch {
setStatus('error');
setError('Network error. Please try again.');
}
}
if (status === 'success') return <p>Thanks! Your message has been sent.</p>;
return (
<form onSubmit={handleSubmit}>
<input type="hidden" name="access_key" value="YOUR_ACCESS_KEY" />
<input type="text" name="name" placeholder="Name" required />
<input type="email" name="email" placeholder="Email" required />
<textarea name="message" placeholder="Message" required />
<input type="checkbox" name="botcheck" className="hidden" style={{ display: 'none' }} tabIndex={-1} autoComplete="off" />
<button type="submit" disabled={status === 'sending'}>{status === 'sending' ? 'Sending...' : 'Send'}</button>
{status === 'error' && <p role="alert">{error}</p>}
</form>
);
}// app/routes/contact.tsx
import { Form, data, useActionData, useNavigation } from 'react-router';
import type { Route } from './+types/contact';
export async function action({ request }: Route.ActionArgs) {
const formData = await request.formData();
if (formData.get('botcheck')) return { ok: true }; // honeypot ticked
const response = await fetch('https://lazyform-api.xvelopers.com/submit', {
method: 'POST',
headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
body: JSON.stringify({
access_key: process.env.LAZYFORM_KEY,
name: formData.get('name'),
email: formData.get('email'),
message: formData.get('message'),
}),
});
const result = await response.json();
if (!result.success) {
return data({ ok: false, error: result.error?.message ?? 'Something went wrong.' }, { status: response.status });
}
return { ok: true };
}
export default function Contact() {
const result = useActionData<typeof action>();
const sending = useNavigation().state === 'submitting';
if (result?.ok) return <p>Thanks! Your message has been sent.</p>;
return (
<Form method="post">
<input type="text" name="name" placeholder="Name" required />
<input type="email" name="email" placeholder="Email" required />
<textarea name="message" placeholder="Message" required />
<input type="checkbox" name="botcheck" className="hidden" style={{ display: 'none' }} tabIndex={-1} autoComplete="off" />
<button type="submit" disabled={sending}>{sending ? 'Sending...' : 'Send'}</button>
{result && !result.ok && <p role="alert">{result.error}</p>}
</Form>
);
}Tips
<form>vs<Form>. Use a plain<form>when posting to Lazyform directly. Remix's<Form>submits to your own route action.- Which one to pick. The browser version keeps allowed websites and per-visitor rate limiting working as designed. The action posts from your server, which sends no
Originfrom your site, so don't combine it with allowed websites. - Environment variables. Keep
LAZYFORM_KEYin your server environment for the action variant.
Where to go next
- React for a plain React component
- Responses for every error code
- Spam protection
- Send submissions to a webhook