Skip to content
Wrenform

Contact forms / Nuxt

Nuxt contact form without a server route

One Nuxt 3 component that posts with $fetch and shows the result in place. It still posts as plain HTML before hydration.

Why Nuxt needs a form backend

The usual Nuxt contact form is a server/api/contact.post.ts handler that calls a mail provider. That needs a server runtime, an API key in private runtime config, your own validation and your own spam checks, for a page that could be prerendered.

With Wrenform the page posts straight from the browser to your endpoint. There is no server route, so the site can be built with nuxt generate and served from any static host. We store each submission, filter spam and email your recipients.

The prompt

Replace YOUR_FORM_ID in both places. Nuxt auto-imports the component, ref and $fetch, so the file needs no import lines. The form keeps action and method, so it still posts as plain HTML before hydration or with JavaScript off.

<!-- components/ContactForm.vue (Nuxt 3): ref and $fetch are auto-imported -->
<script setup lang="ts">
const status = ref<"idle" | "sending" | "sent" | "error">("idle");

async function onSubmit(e: Event) {
  const form = e.target as HTMLFormElement;
  status.value = "sending";
  try {
    await $fetch("https://wrenform.com/f/YOUR_FORM_ID", {
      method: "POST",
      headers: { Accept: "application/json" },
      body: new FormData(form),
    });
    status.value = "sent";
    form.reset();
  } catch {
    status.value = "error";
  }
}
</script>

<template>
  <form action="https://wrenform.com/f/YOUR_FORM_ID" method="POST" @submit.prevent="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">
      <span v-if="status === 'sent'">Thanks, your message was sent.</span>
      <span v-if="status === 'error'">Something went wrong. Please try again.</span>
    </p>
  </form>
</template>

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: "nuxt": 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 components/ContactForm.vue and replace YOUR_FORM_ID, or build the endpoint from useRuntimeConfig().public.wrenformId.
  3. Use <ContactForm /> in pages/contact.vue.
  4. Build with nuxt build or nuxt generate, 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.

Before hydration, or with JavaScript off, 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, such as https://example.com/thanks. See redirects.

Where messages go: every real submission is emailed to your recipients and kept in the dashboard inbox. On Pro and Agency plans, a webhook can also send each one to your own server.

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 Nuxt 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 Nuxt server route 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.
Does it work with nuxt generate and static hosting?
Yes. The component has no server code, so the page can be prerendered and served from any static host.
Why $fetch and not useFetch?
useFetch is for loading data when a page renders. A form sends once, on submit, so $fetch is the right call.
Where do I keep the form ID?
In runtimeConfig.public in nuxt.config.ts, which you can override with NUXT_PUBLIC_WRENFORM_ID. It is not a secret.
Does it work with nuxi dev?
Yes. Leave allowed origins empty while you test, or add http://localhost:3000.

Next steps