Skip to content
Lazyform
Docs menu

Frameworks and builders

Nuxt

Add a Lazyform contact form to a Nuxt 3 or 4 app, posting from the browser or through a server route.

Nuxt can post to Lazyform straight from the browser, so you don't need a server route. If you'd rather keep the key on the server, a small server route works too. The examples work in Nuxt 3 and Nuxt 4.

Before you start

Get an access key: type your email on the homepage for an instant key, or sign in and create a form. Replace YOUR_ACCESS_KEY with your key (it starts with lf_).

The minimal form

components/ContactForm.vue
<template>
  <form action="https://lazyform-api.xvelopers.com/submit" method="POST">
    <input type="hidden" name="access_key" value="YOUR_ACCESS_KEY" />
    <input type="text" name="name" placeholder="Name" required />
    <input type="email" name="email" placeholder="Email" required />
    <textarea name="message" placeholder="Message" required></textarea>
    <input type="checkbox" name="botcheck" class="hidden" style="display: none" tabindex="-1" autocomplete="off" />
    <button type="submit">Send</button>
  </form>
</template>

In Nuxt 4 the default source folder is app/, so put components in app/components/.

From the browser or through a server route

vue
<!-- components/ContactForm.vue -->
<script setup lang="ts">
const config = useRuntimeConfig();
const fields = reactive({ name: '', email: '', message: '', botcheck: false });
const status = ref<'idle' | 'sending' | 'success' | 'error'>('idle');
const error = ref('');

async function submit() {
  status.value = 'sending';
  try {
    await $fetch('https://lazyform-api.xvelopers.com/submit', {
      method: 'POST',
      headers: { Accept: 'application/json' },
      body: { access_key: config.public.lazyformKey, ...fields, botcheck: fields.botcheck ? 'on' : '' },
    });
    status.value = 'success';
  } catch (err: any) {
    status.value = 'error';
    error.value = err?.data?.error?.message ?? 'Something went wrong.';
  }
}
</script>

<template>
  <p v-if="status === 'success'">Thanks! Your message has been sent.</p>
  <form v-else @submit.prevent="submit">
    <input v-model="fields.name" type="text" placeholder="Name" required />
    <input v-model="fields.email" type="email" placeholder="Email" required />
    <textarea v-model="fields.message" placeholder="Message" required></textarea>
    <input v-model="fields.botcheck" type="checkbox" class="hidden" style="display: none" tabindex="-1" autocomplete="off" />
    <button type="submit" :disabled="status === 'sending'">{{ status === 'sending' ? 'Sending...' : 'Send' }}</button>
    <p v-if="status === 'error'" role="alert">{{ error }}</p>
  </form>
</template>

$fetch sends objects as JSON and throws on error statuses, so the Lazyform error object is on err.data.error.

Tips

  • Runtime config. Add the key to nuxt.config.ts: runtimeConfig: { lazyformKey: '', public: { lazyformKey: '' } }, then set NUXT_LAZYFORM_KEY or NUXT_PUBLIC_LAZYFORM_KEY in .env.
  • Which one to pick. The browser version keeps allowed websites and per-visitor rate limiting working as designed. A server route posts from your server, which sends no Origin from your site, so don't combine it with allowed websites.
  • Static hosting. With nuxt generate there is no server, so use the browser version.

Where to go next