Contact forms / Vue
Vue contact form without a backend
One Vue 3 single-file component that posts with fetch and shows the result in place. No server, no API route, no email package.
Why Vue needs a form backend
A Vue app built with Vite is a single-page app: it runs in the visitor's browser, and the build is a folder of static files. There is nothing in the project to receive a contact form, and an email API can't be called from the browser without exposing its secret key.
The usual fix is a small backend or a serverless function that holds the key, validates the input, fights spam and calls the email service. That is a second deployment to run and secure for one form.
With Wrenform the component posts straight to your endpoint. The form ID is public by design, so it can sit in client code, and Allowed origins stop other sites from using it. We store each submission, filter spam and email your recipients.
The prompt
Replace YOUR_FORM_ID with the ID of your form. @submit.prevent stops the page from reloading, and the component sends FormData with Accept: application/json, so the answer is JSON: { "ok": true } on success, or an error with a stable code.
<!-- ContactForm.vue (Vue 3 / Nuxt) -->
<script setup>
import { ref } from "vue";
const status = ref("idle");
async function onSubmit(e) {
const form = e.target;
status.value = "sending";
try {
const res = await fetch("https://wrenform.com/f/YOUR_FORM_ID", {
method: "POST",
headers: { Accept: "application/json" },
body: new FormData(form),
});
status.value = res.ok ? "sent" : "error";
if (res.ok) form.reset();
} catch {
status.value = "error";
}
}
</script>
<template>
<form @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
- Create a form (free) and copy its form ID. No account yet? Ask your AI tool to create a quick form with
framework: "vue": one request returns your endpoint and a ready snippet. Click Confirm in the email from Wrenform, and messages start arriving. - Save the component as
src/components/ContactForm.vueand replaceYOUR_FORM_ID, or build the URL fromimport.meta.env.VITE_WRENFORM_ID. - Render
<ContactForm />on your contact page. With Vue Router, give it its own/contactroute. - 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.
Each input needs a name attribute: that is what FormData sends. v-model alone doesn't add one, so a form with only v-model bindings arrives empty and is rejected with empty_submission. You can keep v-model for validation as long as the name stays.
Deployment notes
- Netlify. Deploy as usual. Netlify only processes forms that carry its own
netlifyordata-netlifyattribute, so it leaves this form alone and the browser posts it to Wrenform. Add yournetlify.appaddress and your custom domain to Allowed origins. - Vercel. Nothing to configure. The Vue 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.devaddress and your custom domain to Allowed origins. If you set a Content-Security-Policy header, addform-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.
The plain HTML fallback
Don't need the inline result? Give the form an action and method="POST" and drop the handler. The browser posts the form, and the visitor lands on our thank-you page, or on your own page if you set Redirect to in the form's settings. See redirects.
<template>
<form action="https://wrenform.com/f/YOUR_FORM_ID" method="POST">
<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">Send</button>
</form>
</template>Where submissions go
FAQ
Can a Vue app send a contact form without a backend?
Do I need v-model on every field?
Where do I keep the form ID?
Does it work with npm run dev?
Next steps
- The full Vue guide: every option, testing, and common problems.
- Nuxt contact form without a server route
- React contact form without a backend
- Pricing: free for 250 submissions a month.