# Contact form for Nuxt

> A Nuxt 3 component that posts with $fetch, shows the result inline, and still works as a plain HTML form before hydration.

Last updated 2026-11-19. Web version: https://wrenform.com/docs/frameworks/nuxt

```vue
<!-- 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](/sign-in) and copy its form ID, or let your AI tool create one [without an account](/docs/quick-forms).
2. Save the snippet as `components/ContactForm.vue` and replace `YOUR_FORM_ID` in both places. Nuxt auto-imports the component, `ref` and `$fetch`, so it needs no import lines.
3. Use it on a page, for example `pages/contact.vue`:

```vue
<template>
  <main>
    <h1>Contact</h1>
    <ContactForm />
  </main>
</template>
```

4. Deploy as usual (`nuxt build` or `nuxt generate`). Then add your site's origin under **Allowed origins** in the form's settings.

**No server route needed.** You don't need a `server/api` handler or a mail provider: the visitor's browser posts straight to Wrenform. The form ID is public by design, so it can live in client code.

**Works before hydration.** The form keeps its `action` and `method`, so a visitor who submits before the page hydrates, or with JavaScript off, still sends the message as a plain HTML post. Set the form's **Success URL** to a thank-you page for that case (see [redirects](/docs/redirects)).

## Keep the form ID in config

To set the ID once, add it to `runtimeConfig.public` and read it in the component:

```ts
export default defineNuxtConfig({
  runtimeConfig: {
    public: { wrenformId: "YOUR_FORM_ID" },
  },
});
```

Then, in the component, build the endpoint with `const endpoint = "https://wrenform.com/f/" + useRuntimeConfig().public.wrenformId;` and use it for both `$fetch` and `:action`. You can override it per environment with `NUXT_PUBLIC_WRENFORM_ID`.

## Test it

Run `npx nuxi dev`, open `/contact` and send the form. You should see the thank-you line, the submission in your dashboard and an email. While testing locally, leave **Allowed origins** empty or add `http://localhost:3000`.

## Common problems

- **CORS error or `origin_not_allowed`.** Add the site's origin, including `https://`, to the form's allowed origins.
- **`empty_submission`.** The inputs need `name` attributes. `v-model` alone doesn't add them.
- **`$fetch` is not defined.** The file is outside a Nuxt app (plain Vue). Use the [Vue guide](/docs/frameworks/vue), which posts with `fetch`.
- **You see Wrenform's own thank-you page.** The form posted before hydration. Set the form's Success URL to your own page.
- **Strict CSP.** Add `connect-src https://wrenform.com` and `form-action https://wrenform.com`.

## Next steps

- [Spam](/docs/spam): the honeypot, the timing check and Turnstile.
- [Fields](/docs/fields): subjects, reply-to and lists.
- [Errors](/docs/errors): every code and its fix.
