Add a contact form to a Vue site

A Vue 3 component can post a form straight to FormKeep with fetch. There is no backend to write and no API key.

What you need

Steps

  1. Create a form in FormKeep and copy its URL from the Setup tab.
  2. Save the component below as ContactForm.vue and put your URL in FORM_URL.
  3. Use <ContactForm /> where the form should appear.
  4. Send a test message and open the form in FormKeep to see it.

The component

<script setup>
import { ref } from 'vue';

const FORM_URL = 'https://formkeep.com/f/YOUR-TOKEN';
const status = ref('idle'); // idle | sending | sent | error

async function submit(event) {
  const form = event.target;
  status.value = 'sending';
  try {
    const response = await fetch(FORM_URL, {
      method: 'POST',
      headers: { Accept: 'application/json' },
      body: new FormData(form),
    });
    if (!response.ok) throw new Error(`FormKeep answered ${response.status}`);
    form.reset();
    status.value = 'sent';
  } catch (error) {
    status.value = 'error';
  }
}
</script>

<template>
  <form @submit.prevent="submit">
    <label>
      Email
      <input name="email" type="email" required />
    </label>
    <label>
      Message
      <textarea name="message" required></textarea>
    </label>
    <button type="submit" :disabled="status === 'sending'">
      {{ status === 'sending' ? 'Sending...' : 'Send' }}
    </button>
    <p v-if="status === 'sent'" role="status">Thanks, we got your message.</p>
    <p v-if="status === 'error'" role="alert">Something went wrong. Please try again.</p>
  </form>
</template>

Do not set a Content-Type header yourself with FormData: the browser adds the multipart boundary. The URL is not a secret, so it can sit in client code; there is no API key to hide.

What happens on submit

The request asks for JSON with Accept: application/json, so FormKeep does not redirect. A stored submission answers 200 with the body null; the page stays where it is and shows its own message. A wrong token answers 404 and a form switched off answers 403, and the code above shows the error message for both. The submission appears in your dashboard and your inbox.

Add file uploads

Add a file input inside the form. new FormData(form) sends it as multipart without any other change.

<input name="resume" type="file">

Each file can be up to 10 MB and a submission can carry up to 50 files. Whether attachments are kept depends on your plan.

Troubleshooting

Looking for something else?

Email us