Vue
Use the official composable, @formstork/vue, to wire up a form in one line.
npm install @formstork/vue
<script setup>
import { useFormstork } from "@formstork/vue";
const { submit, isSubmitting, isSuccess, message } = useFormstork({
accessKey: "YOUR_ACCESS_KEY",
});
</script>
<template>
<p v-if="isSuccess">Thanks, {{ message }}</p>
<form v-else @submit="submit">
<input type="text" name="name" required />
<input type="email" name="email" required />
<textarea name="message" required></textarea>
<button :disabled="isSubmitting">
{{ isSubmitting ? "Sending..." : "Send" }}
</button>
</form>
</template>
The composable collects the form fields automatically and posts them for you. It returns reactive refs: state, message, and the flags isSubmitting / isSuccess / isError.
Without the composable
If you’d rather not add a dependency, post the form directly:
async function onSubmit(e) {
e.preventDefault();
await fetch("https://api.formstork.com/submit", {
method: "POST",
body: new FormData(e.target),
headers: { Accept: "application/json" },
});
}