You built a SvelteKit site, exported it with adapter-static, and now the contact page needs to actually send something somewhere. The form action you wrote in +page.server.ts works in dev, then fails or disappears in the static build, and the contact page ships as a form that goes nowhere. Every day it stays that way, real enquiries are lost without any error on your side.
A SvelteKit contact form without a backend is a form whose submission goes from the browser straight to a hosted endpoint instead of to a server route you run yourself. SimpleForm is a hosted form backend for static sites: you point a form at an endpoint URL and it handles spam filtering, email delivery, storage and webhooks. This guide shows the full setup in a static SvelteKit project.
Why can't you use SvelteKit form actions on a static site?
SvelteKit form actions need a running server, and a static build does not have one. The SvelteKit adapter-static documentation describes the adapter as prerendering your whole site to plain files, and a +page.server.ts action is code that has to execute on each POST.
That leaves you three options: switch to a server adapter and host a Node or edge runtime, write a serverless function just for one form, or post to an external endpoint. The third option keeps the site fully static, so it is the only one that adds no hosting or deployment work.
How do you build a SvelteKit contact form step by step?
You build it in five steps: create the endpoint, store its URL in a public env variable, write the form component, submit with fetch, and render the result. The whole component is about forty lines.
- Create a form in your SimpleForm dashboard and copy its endpoint URL. It looks like
https://simpleform.dev/f/TOKEN. - Add the URL to
.envasPUBLIC_FORM_ENDPOINT. SvelteKit only exposes variables with thePUBLIC_prefix to client code. - Create a component with a real
<form>, and give every input anameattribute. - On submit, call
preventDefault(), sendnew FormData(form)with anAccept: application/jsonheader, and read the JSON reply. - Set a status variable to
sentorerrorand render a message for it.
Here is the component using Svelte 5 syntax. On Svelte 4, replace onsubmit with on:submit|preventDefault and $state with a plain let.
<script>
import { PUBLIC_FORM_ENDPOINT } from '$env/static/public';
let status = $state('idle');
async function submit(event) {
event.preventDefault();
const form = event.currentTarget;
status = 'sending';
try {
const res = await fetch(PUBLIC_FORM_ENDPOINT, {
method: 'POST',
headers: { 'Accept': 'application/json' },
body: new FormData(form)
});
const data = await res.json();
if (res.ok && data.success) {
form.reset();
status = 'sent';
} else {
status = 'error:' + res.status;
}
} catch {
status = 'error:network';
}
}
</script>
<form onsubmit={submit}>
<label>Name <input name="name" required></label>
<label>Email <input name="email" type="email" required></label>
<label>Message <textarea name="message" required></textarea></label>
<button disabled={status === 'sending'}>Send</button>
</form>
{#if status === 'sent'}<p role="status">Thanks, message received.</p>{/if}The SimpleForm docs state that the endpoint accepts URL-encoded posts, multipart posts and JSON, and that a JSON reply carries a success flag. Sending FormData means you never set a Content-Type header yourself, and the browser builds the multipart boundary correctly.
Writing this by hand for every project gets repetitive, especially the spam handling, email routing and storage behind the form. That is the part SimpleForm replaces: the endpoint does the server work, and the component above is the only code you own. The SimpleForm documentation lists the request formats and response fields in full.
What should the form do with each response code?
It should treat the HTTP status as the source of truth and show a different message for each failure. The SimpleForm docs list seven codes, and each one points at a different fix.
| Status | Meaning | What to show or do |
|---|---|---|
| 200 | Submission accepted, or caught by the honeypot and silently dropped | Show the thank-you message |
| 400 | Missing or invalid form data | Ask the visitor to check the fields |
| 402 | Plan submission limit exceeded | Show a generic failure; fix your plan, not the code |
| 403 | Disallowed origin domain | Check the domain restriction list |
| 404 | Endpoint token not found or inactive | Check the env variable and the form status |
| 429 | Rate limit exceeded | Ask the visitor to wait and retry |
A 200 does not always mean a stored submission, because a honeypot catch also returns 200. A visitor never sees the difference, and neither should your UI, but it matters when you debug a missing entry.
Visitors should never see raw status codes. Map them to plain sentences in the component and log the code to the console so you can read it when something breaks.
Where should the endpoint URL live in a SvelteKit project?
It should live in a PUBLIC_ environment variable, read through $env/static/public. The URL is not a secret, because it has to appear in the HTML or JavaScript the browser downloads, so the real protection is restricting which origins may post to it, not hiding it.
Using an env variable still earns its place. It lets you point a preview deploy at a separate test form, so your staging experiments never land in the production inbox or count against its monthly limit. Domain restriction, available on the Pro plan, then rejects posts from any other origin with a 403.
With static builds, the value is baked in at build time. If you change the variable in your host dashboard, you must trigger a new build before it takes effect.
What breaks most often in a static SvelteKit form?
The most common failures are missing name attributes, a stale build, and a 403 after you add domain restriction. Each one shows up as a form that looks fine and sends nothing useful.
A missing name attribute is the quietest. Inputs without a name are not included in FormData, so the submission arrives empty or partial. Bind each input to a name and test with a real submit before launch.
The second is a stale build. You rotate the endpoint token, update the env variable, and the live site still posts to the old URL because nobody rebuilt it. That produces a 404.
The third is the origin check. If you restrict the endpoint to your production domain and then test from a preview URL, the preview gets a 403. Add the preview domain to the allowed list, or use a separate form for previews.
Could you just write your own +server.ts endpoint instead?
You could, and for some projects it is the right call. A +server.ts route gives you full control, but it forces a server adapter, a host that runs code, and your own answers to spam, email deliverability, rate limiting and storage. If your site already runs on a Node or edge host and you want to own that logic, build it.
If the site is static and the form is the only dynamic thing on it, a hosted endpoint is less to maintain. The trade-off is that you depend on an outside service, so keep the endpoint URL in one env variable and the component small enough that moving away later is a one-file change.
Ready to wire it up?
Create a free SimpleForm account, make one form, and paste its endpoint into PUBLIC_FORM_ENDPOINT. The free sign-up needs no credit card, and the free plan includes 100 submissions per month and 3 forms. After you register you land in the dashboard, where the endpoint URL is ready to copy. Send one test message from your site, then check it arrives. If you later need more volume, webhooks or domain restriction, the pricing page lists what each plan includes.
Frequently asked questions
No, not for submissions. Form actions are server code that runs on each POST, and adapter-static prerenders the site into plain files with no server to run them. Post the form from the browser to an external endpoint with fetch, or switch to a server adapter and host a runtime.
Yes, because the URL has to be visible to the browser anyway. Anyone can read it from your page source, so security comes from restricting which origins may post to it and from spam filtering on the endpoint. Treat the URL as public and never put API keys in a PUBLIC_ variable.
Usually the build did not pick up your environment variable, or the endpoint restricts origins and your deployed domain is not on the list. Static builds bake env values in at build time, so redeploy after changing them. A 404 points to a wrong URL, and a 403 points to the origin list.
FormData is enough and is the simplest choice. SimpleForm accepts URL-encoded, multipart and JSON bodies. With FormData you skip setting a Content-Type header, because the browser sets the multipart boundary itself. Add an Accept: application/json header so the endpoint replies with JSON you can read in code.
Submit the real form once from the deployed site, then confirm the entry appears in the dashboard and the notification email arrives. Also test a request with a wrong token to confirm your UI shows the error state for a 404 instead of claiming success. Do both before you announce the page.