How to make an HTML form work without a backend
An HTML form needs a server to receive what people type. Here are the three ways to get one, plus a complete working contact form you can copy.
You wrote a contact form in HTML, pressed the submit button, and nothing useful happened. The page reloaded, or showed an error, and no message arrived anywhere. That is expected: HTML can describe a form, but it cannot receive one.
This guide explains what is missing, the three ways to fill the gap, and a complete example you can paste into any page.
Why an HTML form needs a server
A <form> element is a set of instructions for the browser. When a visitor presses the submit button, the browser collects every field that has a name attribute and sends the values to the address in the form's action attribute. If method="POST", the values travel in the body of an HTTP request, which is the message format browsers and servers use to talk to each other.
The request looks roughly like this:
POST /contact HTTP/1.1
Host: example.com
Content-Type: application/x-www-form-urlencoded
name=Ada&email=ada%40example.com&message=HelloSomething has to be listening at that address. It has to read the request, decide whether it is acceptable, save it or email it to you, and send a response back. That "something" is what people mean by a backend: code that runs on a server instead of in the visitor's browser.
Static hosting (the kind that serves HTML, CSS and JavaScript files and nothing else) has no such code. The files are delivered as they are. A form on a static site that points at its own page has nothing on the other end.
It is tempting to solve this in the browser with JavaScript alone, for example by calling an email service directly. That does not work safely. Anything in your page's JavaScript is visible to every visitor, including any password or API key you would need to send email or write to a database.
Three ways to receive form submissions
Option | What you build | What you maintain |
|---|---|---|
Your own server | An application (in Node.js, PHP, Python or similar) with a route that handles the POST | The server, its updates, spam filtering, storage, email delivery |
A serverless function | One small function, deployed to a cloud provider, that handles the POST | The function, plus accounts for storage and email, plus your own spam filtering |
A form backend | Nothing. You set the form's | The form settings in a dashboard |
Your own server gives you complete control. It makes sense when you already run one for other reasons, or when a submission has to trigger logic that is specific to your product, such as creating a user account.
A serverless function is a single piece of server code that a cloud provider runs for you on demand. It removes the need to manage a machine, but you still write the code that parses the request, validates the fields, blocks spam, stores the data and sends the notification email.
A form backend is a hosted service that already does all of that. You keep writing your own HTML, and the service provides the receiving end. For contact forms, sign-up forms, surveys and applications, this is usually the least work. We cover the idea in more depth in what is a form backend.
A complete working example
FormDB is a form backend. Each form you create gets an endpoint (a URL that accepts submissions) in this shape:
https://api.formdb.io/f/your-form-idTo get one, create a free account, create a form, and copy the endpoint from the form's Setup tab. No API key is involved: the form id in the URL is the only identifier.
Then point your form at it. This is a complete page:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Contact</title>
</head>
<body>
<h1>Contact us</h1>
<form action="https://api.formdb.io/f/your-form-id" method="POST">
<label for="name">Name</label>
<input id="name" type="text" name="name" required>
<label for="email">Email</label>
<input id="email" type="email" name="email" required>
<label for="message">Message</label>
<textarea id="message" name="message" rows="6" required></textarea>
<input type="text" name="_gotcha" tabindex="-1" autocomplete="off" style="display:none">
<button type="submit">Send</button>
</form>
</body>
</html>Replace your-form-id with your own id and open the page. A few details matter:
actionandmethod="POST"tell the browser where and how to send the data.- Every field needs a
name. Fields without one are not sent at all. The names become the keys you see in your inbox. - A field named
emailhas a useful side effect on FormDB: the notification email uses that address as its Reply-To, so you can answer the sender by pressing reply. - The hidden
_gotchafield is a honeypot. People never see it, so it stays empty. Many spam bots fill in every field they find, and FormDB silently drops any submission where_gotchahas a value.
What happens when someone submits
With the form above, the browser posts the data to FormDB and the visitor sees a hosted thank-you page. If you would prefer to send people to a page on your own site, set a redirect URL in the form's settings.
On your side:
- The submission appears in the form's inbox in the dashboard.
- A notification email goes to the email address of the workspace owner.
- If the form has fields defined in the form builder, the values are checked on the server first. See validation rules for what can be checked.
The full request and response details are in the HTML forms guide.
Submitting without leaving the page
A plain form causes a full page navigation. If you would like the visitor to stay on the page and see a message in place, send the same data with fetch, the browser's built-in function for making HTTP requests from JavaScript.
Add an id to the form (id="contact-form"), then place this after it:
<p id="form-status" role="status"></p>
<script>
const contactForm = document.querySelector("#contact-form");
const formStatus = document.querySelector("#form-status");
contactForm.addEventListener("submit", async (event) => {
event.preventDefault();
formStatus.textContent = "Sending...";
try {
const response = await fetch(contactForm.action, {
method: "POST",
headers: { Accept: "application/json" },
body: new FormData(contactForm),
});
const body = await response.json();
if (response.ok) {
contactForm.reset();
formStatus.textContent = "Thanks, your message was sent.";
} else {
formStatus.textContent = body.error.message;
}
} catch (err) {
formStatus.textContent = "Could not reach the server. Please try again.";
}
});
</script>The Accept: application/json header asks FormDB to answer with JSON instead of a web page. A successful submission returns status 201 and this body:
{ "ok": true, "id": "..." }A rejected one returns an error object with a readable message:
{ "ok": false, "error": { "code": "validation_failed", "message": "Email must be a valid email address." } }Because the form still has its action and method, it keeps working for visitors whose JavaScript fails to load. The script is an improvement on top, not a requirement. More patterns are in JavaScript and AJAX.
Things to know before you launch
- The Free plan accepts 250 submissions a month, keeps them for 30 days and includes 100 MB of file storage. Paid plans start at 2,500 a month with unlimited retention, more storage and integrations. See pricing.
- When a monthly limit is reached, further submissions are held, up to one extra month's worth, and delivered when you upgrade or the quota resets. The owner gets an email at 80% and at 100% of the limit.
- A honeypot stops unsophisticated bots only. If spam becomes a problem, read how to stop contact form spam.
Next steps
The quickstart walks through creating a form and sending a first submission in a few minutes. If you have a page with a form that currently goes nowhere, create a free account, swap in your endpoint, and submit it once to see the result in your inbox.