VitePress contact form without a server
Add a contact form to a VitePress site with one Vue component. Works on GitHub Pages and any static host. Stored in Frankfurt.
VitePress builds static HTML, and it is usually deployed to GitHub Pages, Cloudflare Pages or another file host. Nothing there can receive the POST when someone clicks "Send".
With Formlane, the form posts straight from the browser to https://smallwerk.com/formlane/api/submit. Formlane stores the message and emails it to the form's notification address, with reply-to set to the sender. Your VitePress site stays fully static.
Quick start
- Sign in to Formlane, create a form and copy its access key (
fl_…). - Add
docs/components/ContactForm.vue(below) and setSITE_URLandFORMLANE_KEYat the top. - Import it in
docs/contact.md. - Add
docs/thanks.md, runnpx vitepress build docs && npx vitepress preview docs, send a test message and check your inbox and the Formlane dashboard. - In the form settings, restrict the form to your production domain, so forms on other websites can't post to it.
Code
<script setup>
import { withBase, useData } from 'vitepress'
// Your site's address (no trailing slash) and your Formlane access key.
// The key is public by design: it only allows sending submissions to this form.
const SITE_URL = 'https://example.com'
const FORMLANE_KEY = 'fl_YOUR_ACCESS_KEY'
const { site } = useData()
const redirect = SITE_URL + withBase('/thanks.html')
</script>
<template>
<form action="https://smallwerk.com/formlane/api/submit" method="POST" accept-charset="UTF-8" class="contact-form">
<input type="hidden" name="access_key" :value="FORMLANE_KEY">
<input type="hidden" name="subject" :value="`New message from ${site.title}`">
<input type="hidden" name="redirect" :value="redirect">
<!-- Honeypot: hidden from people, leave it unchecked -->
<input type="checkbox" name="botcheck" style="display:none" tabindex="-1" autocomplete="off">
<label for="cf-name">Name</label>
<input id="cf-name" type="text" name="name" autocomplete="name" required>
<label for="cf-email">Email</label>
<input id="cf-email" type="email" name="email" autocomplete="email" required>
<label for="cf-message">Message</label>
<textarea id="cf-message" name="message" rows="5" required></textarea>
<button type="submit">Send</button>
</form>
</template>
<style scoped>
.contact-form { display: grid; gap: 8px; max-width: 480px; }
.contact-form input, .contact-form textarea { border: 1px solid var(--vp-c-divider); border-radius: 6px; padding: 8px; }
.contact-form button { background: var(--vp-c-brand-1); color: var(--vp-c-white); border-radius: 6px; padding: 8px 16px; }
</style>--- title: Contact --- <script setup> import ContactForm from './components/ContactForm.vue' </script> # Contact Questions? Write us. <ContactForm />
# Thanks Thanks for your message. We'll get back to you soon.
The key is public by design: it only allows sending submissions to this one form, so it is fine in your repository and in the built HTML. VitePress renders the component into the static HTML at build time, so the form also works without JavaScript.
The thank-you page
After a successful submission the redirect field sends visitors to the thank-you page. It has to be an absolute http(s) URL, which is why the component joins SITE_URL with withBase('/thanks.html'). Without a redirect, Formlane uses the default redirect from your form settings, or its own hosted thank-you page.
- On a GitHub Pages project site, set
base: '/repo-name/'in.vitepress/config.mjs. The redirect becomeshttps://example.com/repo-name/thanks.html. - If you use
cleanUrls: trueand your host serves pages without.html, change the path to/thanks. - The redirect always points to
SITE_URL, also duringvitepress dev. Test the full flow withvitepress previewor on a preview deploy.
Optional: stay on the page
If you'd rather show a message without a page change, send the form with fetch(). With Accept: application/json, Formlane answers {"success": true, "message": "Form submitted successfully", "id": "…"} or {"success": false, "error": "limit_reached", "message": "…"} with a 4xx/5xx status. message is always English, so the component shows its own text per error code.
<script setup>
import { ref } from 'vue'
const FORMLANE_KEY = 'fl_YOUR_ACCESS_KEY'
const MESSAGES = {
limit_reached: "This form can't take more messages this month. Please email us directly.",
rate_limited: 'Too many messages in a short time. Please try again in a few minutes.',
}
const FALLBACK = "Sorry, that didn't work. Please try again later."
const status = ref('idle') // idle | sending | sent | error
const error = ref('')
async function onSubmit(event) {
status.value = 'sending'
try {
const res = await fetch(event.target.action, {
method: 'POST',
headers: { Accept: 'application/json' },
body: new FormData(event.target),
})
const json = await res.json().catch(() => ({}))
// Spam caught by the honeypot or the content rules also gets success: true.
if (json.success) { status.value = 'sent'; return }
error.value = MESSAGES[json.error] || FALLBACK
} catch {
error.value = FALLBACK
}
status.value = 'error'
}
</script>
<template>
<p v-if="status === 'sent'">Thanks! We'll get back to you.</p>
<form v-else action="https://smallwerk.com/formlane/api/submit" method="POST" @submit.prevent="onSubmit">
<input type="hidden" name="access_key" :value="FORMLANE_KEY">
<input type="checkbox" name="botcheck" style="display:none" tabindex="-1" autocomplete="off">
<label for="cfi-name">Name</label>
<input id="cfi-name" type="text" name="name" autocomplete="name" required>
<label for="cfi-email">Email</label>
<input id="cfi-email" type="email" name="email" autocomplete="email" required>
<label for="cfi-message">Message</label>
<textarea id="cfi-message" name="message" rows="5" required></textarea>
<button type="submit" :disabled="status === 'sending'">{{ status === 'sending' ? 'Sending…' : 'Send' }}</button>
<p v-if="status === 'error'" role="alert">{{ error }}</p>
</form>
</template>Without JavaScript, the browser still posts the form normally.
Spam protection without a captcha
- Honeypot: the hidden
botcheckcheckbox. If a bot ticks it, Formlane returns a normal success response and stores nothing. - Rate limit: 10 submissions per 10 minutes per visitor and form.
- Content rules: messages with 4 or more links, link markup or typical spam phrases go to a separate spam tab. Spam doesn't count toward your monthly limit.
- Allowed domains: limit the form to your own domain in its settings.
Limits worth knowing
- Up to 64 KB per submission, 50 fields and 10,000 characters per field.
- Content types:
application/x-www-form-urlencoded,multipart/form-data(text fields only) andapplication/json. - File uploads are not supported yet. If your form needs attachments, use one of the alternatives below.
Alternatives, honestly compared
| Option | Good fit when | Trade-off |
|---|---|---|
| Formlane | VitePress on GitHub Pages or any static host; you want email alerts and a dashboard without running code | No file uploads yet; on the Free plan, notification emails and the hosted thank-you page carry a "Powered by Formlane" link |
| Netlify Forms | Your VitePress site is deployed on Netlify anyway | Only works on Netlify hosting, not on GitHub Pages; usage is billed in Netlify's credit plans |
| Your own serverless function (Netlify/Vercel/Cloudflare) | You want full control over storage and email | GitHub Pages can't run it, so the function lives on a second host; you maintain it, an email provider account and spam protection yourself |
| Formspree | You want the best-known form backend and its integrations | Free plan: 50 submissions a month (plans page, checked 26.10.2026) |
| Web3Forms | You need many forms on the free tier | Free plan: 250 submissions a month (checked 26.10.2026) |
Where the data is stored
Stored in Frankfurt, in a Supabase database in the eu-central-1 region. The app runs on Vercel: our server functions run in Frankfurt (fra1); static files and edge routing are served by Vercel's global network. Notification emails are sent through Resend, a US company. All providers are listed in the privacy policy. Formlane is run by Mindcaptain Services OÜ in Tallinn, Estonia. A data processing agreement is included in the Terms (Art. 28 GDPR, smallwerk.com/dpa), and IP hashes are deleted after 30 days. Add the contact form to your own privacy policy, and delete old submissions in the dashboard when you no longer need them.
Pricing
Free: 250 submissions a month and up to 5 forms. Starter: $8/month for 2,500 submissions. Pro: $19/month for 25,000 submissions. Prices are in USD incl. VAT where applicable (also available in EUR). A read-only REST API and MCP server are included on every plan, including Free.
Related guides
FAQ
Can VitePress send email from a contact form?
Not on its own: VitePress builds static files. A form backend receives the POST and sends the email for you.
Can I write the form as plain HTML in Markdown instead of a component?
Yes, VitePress allows HTML in Markdown. The component is only there to build the absolute redirect URL with withBase(), which matters when your site has a base.
Does it work with the default theme?
Yes. The component uses the theme's CSS variables, so it follows light and dark mode.
Is it safe to put the access key in the component?
Yes. The Formlane access key is public by design and only allows sending submissions to that one form. Restrict the form to your domain in its settings so other sites can't use it.
What happens when I reach the monthly limit?
New submissions are rejected with the error limit_reached until the next calendar month or an upgrade. Stored submissions stay.
Get your access key
Free for 250 submissions a month. Submissions stored in Frankfurt.
Get your access key