Skip to content
Wrenform

Contact forms / SvelteKit

SvelteKit contact form without a mail server

One +page.svelte with a real HTML form. It posts without JavaScript, and shows the result in place once the page is hydrated.

Why SvelteKit needs a form backend

The usual SvelteKit contact form is a form action in +page.server.js that calls a mail provider. That needs a server adapter, an API key in a private environment variable, your own validation and your own spam checks, for a page that could be prerendered.

With Wrenform the form posts straight from the browser to your endpoint. There is no form action and no +server.js, so the route can use export const prerender = true and adapter-static. We store each submission, filter spam and email your recipients.

The prompt

Replace YOUR_FORM_ID with the ID of your form. The form keeps action and method, so it still posts as plain HTML before hydration or with JavaScript off; once hydrated, onsubmit sends it with fetch and shows the result in place.

<!-- src/routes/contact/+page.svelte (Svelte 5) -->
<script>
  const endpoint = "https://wrenform.com/f/YOUR_FORM_ID";
  let status = $state("idle");

  async function onsubmit(e) {
    e.preventDefault();
    const form = e.currentTarget;
    status = "sending";
    try {
      const res = await fetch(endpoint, {
        method: "POST",
        headers: { Accept: "application/json" },
        body: new FormData(form),
      });
      status = res.ok ? "sent" : "error";
      if (res.ok) form.reset();
    } catch {
      status = "error";
    }
  }
</script>

<form action={endpoint} method="POST" {onsubmit}>
  <label>Name <input type="text" name="name" autocomplete="name" required /></label>
  <label>Email <input type="email" name="email" autocomplete="email" required /></label>
  <label>Message <textarea name="message" required></textarea></label>
  <input type="text" name="_honey" style="display:none" tabindex="-1" autocomplete="off" />
  <button type="submit" disabled={status === "sending"}>Send</button>
  <p role="status">
    {#if status === "sent"}Thanks, your message was sent.{/if}
    {#if status === "error"}Something went wrong. Please try again.{/if}
  </p>
</form>

Steps

  1. Create a form (free) and copy its form ID. No account yet? Ask your AI tool to create a quick form with framework: "svelte": one request returns your endpoint and a ready snippet. Click Confirm in the email from Wrenform, and messages start arriving.
  2. Save the snippet as src/routes/contact/+page.svelte and replace YOUR_FORM_ID, or read it from PUBLIC_WRENFORM_ID in $env/static/public.
  3. Optional: add export const prerender = true in src/routes/contact/+page.js.
  4. Build, deploy, and add your site to Allowed origins.

Spam handling

Spam filtering is on for every form, with no CAPTCHA: a hidden honeypot field, a timing check, rate limits per visitor, and a content score for links, keywords and gibberish. Spam goes to a separate tab and is never emailed. See how spam filtering works.

Without JavaScript the visitor lands on our thank-you page after sending. To bring them back to your site, set Redirect to in the form's settings, or add a hidden _redirect field with a full URL such as https://example.com/thanks. See redirects.

Deployment notes

  • Netlify. Deploy as usual. Netlify only processes forms that carry its own netlify or data-netlify attribute, so it leaves this form alone and the browser posts it to Wrenform. Add your netlify.app address and your custom domain to Allowed origins.
  • Vercel. Nothing to configure. The SvelteKit build stays static; you don't need a serverless function for the form. Add your production domain to Allowed origins. Preview deployments get their own addresses, so leave the list empty while you test them, or add each one.
  • Cloudflare Pages. No Pages Function needed. Add your pages.dev address and your custom domain to Allowed origins. If you set a Content-Security-Policy header, add form-action https://wrenform.com.
  • GitHub Pages. GitHub Pages serves static files only, which is all this form needs. Add https://<user>.github.io (or your custom domain) to Allowed origins. The origin is the host only, without the repository path.

FAQ

Do I need a SvelteKit form action to send email?
No. The browser posts the form to Wrenform, which stores it and emails you. You don't run server code or hold a mail API key.
Can I use use:enhance?
Not on this form. use:enhance is built for your own form actions and expects a SvelteKit action result back. The onsubmit handler in the snippet gives the same progressive enhancement against Wrenform's JSON answer.
Does it work with adapter-static and prerendering?
Yes. The page has no server code, so it can be prerendered and served from any static host.
Does it work on Svelte 4?
Yes, with two changes: let status = "idle" instead of $state("idle"), and on:submit={onsubmit} instead of {onsubmit}. The handler already calls preventDefault.
Does it work with npm run dev?
Yes. Leave allowed origins empty while you test, or add http://localhost:5173.

Next steps