Form backend for React
Post your React form straight from the browser to a Formboost endpoint with fetch(). No API route, no server of your own, and no email credentials in your bundle — submissions are stored, screened for spam and delivered to you.
Reviewed by Ritu Fadadu · Last reviewed
Why React forms need a backend
A React app built with Vite or Create React App ships as static files, so a form has nowhere to post. The usual fixes are an API route or serverless function you now have to host, or a client-side email library that only sends an email — nothing is stored, and nothing screens out bots.
One form endpoint instead
Keep the form in React and send it to your Formboost endpoint with fetch(). The endpoint answers 202 at once; Formboost stores the submission, screens it for spam and delivers it to email, Slack, Discord or Telegram. The endpoint is public by design, so there is no key to hide.
Formboost is a form backend: the form endpoint receives the submission, screens it for spam, stores it and delivers it — the same for React as for any other frontend.
Setup in 5 Steps
Create a free form in the Formboost dashboard and copy its endpoint
Put it in an environment variable — VITE_FORMBOOST_ENDPOINT in Vite
On submit, read the form with FormData and send it as JSON with Accept: application/json
Show a sending state and a result from the response, and reset the form on success
Submit once from the deployed app and check the submission in your dashboard
Code Example
import { useState } from "react";
// Your form's endpoint from the Formboost dashboard. It is public, not a secret.
const ENDPOINT = import.meta.env.VITE_FORMBOOST_ENDPOINT;
export default function ContactForm() {
const [status, setStatus] = useState("idle"); // idle | sending | sent | error
async function handleSubmit(event) {
event.preventDefault();
const form = event.currentTarget;
// Send JSON. Passing the FormData object itself sends multipart, which the endpoint refuses (415).
const data = Object.fromEntries(new FormData(form));
if (data.email) data._replyto = data.email; // replying to the notification answers the visitor
setStatus("sending");
try {
const response = await fetch(ENDPOINT, {
method: "POST",
headers: { "Content-Type": "application/json", Accept: "application/json" },
body: JSON.stringify(data),
});
setStatus(response.ok ? "sent" : "error");
if (response.ok) form.reset();
} catch {
setStatus("error");
}
}
return (
<form onSubmit={handleSubmit}>
<label htmlFor="name">Name</label>
<input id="name" name="name" autoComplete="name" required />
<label htmlFor="email">Email</label>
<input id="email" name="email" type="email" autoComplete="email" required />
<label htmlFor="message">Message</label>
<textarea id="message" name="message" rows={5} required />
{/* Honeypot: hidden from people, filled in by bots */}
<input type="text" name="_honey" tabIndex={-1} autoComplete="off" aria-hidden="true"
style={{ position: "absolute", left: "-9999px" }} />
<button type="submit" disabled={status === "sending"}>
{status === "sending" ? "Sending…" : "Send"}
</button>
<p role="status">
{status === "sent" && "Thanks — your message has been sent."}
{status === "error" && "Something went wrong. Please try again."}
</p>
</form>
);
}React: the details
What the endpoint expects from fetch()
| You send | You get back |
|---|---|
POST with Content-Type: application/json and Accept: application/json | 202 with { success: true, message, requestId } — the submission is accepted and processed in the background |
A body with nothing but _-prefixed fields | 400 with name: "EMPTY_SUBMISSION" |
A FormData object as the body (multipart) | 415 with name: "UNSUPPORTED_CONTENT_TYPE" |
| Too many requests from one address in a minute | 429 with name: "RATE_LIMITED" and a RateLimit-Reset header |
Requests are accepted from any origin, so there is nothing to configure for CORS and no proxy to write. A 202 means the request was accepted, not that the endpoint ID is right — check your first submission in the dashboard.
Common mistakes
| Symptom | Cause | Fix |
|---|---|---|
415 Unsupported Media Type | body: new FormData(form) sends multipart (MDN: FormData) | Convert with Object.fromEntries(new FormData(form)) and send JSON |
| Only one ticked checkbox arrives | Object.fromEntries keeps the last value of a repeated name | Read groups with formData.getAll("topics") and send the array |
| The page reloads and the answers appear in the URL | event.preventDefault() is missing, so the browser does a normal GET submit | Call preventDefault() first in the submit handler |
The request goes to /undefined on your own site | The environment variable was not set when the app was built | Set VITE_FORMBOOST_ENDPOINT in your host's build settings, then rebuild |
| Two identical submissions | A double click on an enabled button | Disable the button while the request is in flight, as in the example |
With react-hook-form
Validation stays where it is; only the request changes. handleSubmit already gives you a plain object, so send it as JSON:
const { register, handleSubmit, reset } = useForm();
const onSubmit = handleSubmit(async (values) => {
const response = await fetch(ENDPOINT, {
method: "POST",
headers: { "Content-Type": "application/json", Accept: "application/json" },
body: JSON.stringify({ ...values, _replyto: values.email }),
});
if (response.ok) reset();
});Want a styled starting point? Every form template has a React version, and the HTML form generator writes a component for whatever fields you need. The React contact form tutorial adds validation messages step by step.
Features That Work Great
Keep going
React setup reference
The endpoint contract, responses and reserved fields, with examples.
React contact form example with validation
A complete worked example, step by step.
HTML form generator
Pick fields and copy the finished form, ready to paste.
AI spam protection for forms
What screens the submissions before they reach you — no CAPTCHA.
All framework guides
Contact form tutorials for every stack.
Frequently Asked Questions
Common questions about using Formboost with React
Do I need a backend server to handle React forms?
No. The browser sends the form to your Formboost endpoint directly, and Formboost does the server-side work: storing, spam screening and delivery. You do not need an API route or a serverless function.
Is it safe to put the endpoint in my React bundle?
Yes. The endpoint is public by design, the same way any form's action is visible in the page. There is no key to protect; spam screening, a honeypot field and a per-IP rate limit protect it instead.
Why does my request fail with 415?
The body was sent as multipart/form-data, which is what fetch sends when you pass a FormData object as the body. Convert it to a plain object and send JSON, as in the example.
Can I use react-hook-form?
Yes. In handleSubmit you already receive a plain object — send it with JSON.stringify and the same headers as the example. Only the request changes; validation stays with react-hook-form.
Start building with Formboost and React
It takes less than a minute to set up. No credit card required.