@formforkio/vue
v1.0.0
Published
Official Vue 3 & Nuxt 3 SDK for FormFork — Reactive useFormFork() composable with built-in Store-and-Forward failover.
Maintainers
Readme
@formforkio/vue
Official Vue 3 & Nuxt 3 Composition API SDK for FormFork.
Provides a lightweight useFormFork composable with automatic Store-and-Forward Fallback Node failover, anti-bot timing verification (_ff_t), domain-scoped embedToken auto-provisioning, and cryptographic fallbackTicket support.
Features
- Vue 3 & Nuxt 3 Ready: Works seamlessly inside
<script setup lang="ts">in both SSR and SPA modes. - Automatic Store-and-Forward Failover:
- Submits to your primary FormFork server (
endpointHost) with a configurabletimeoutMs(6000msdefault). - Automatically fails over to your Store-and-Forward Fallback Node (
fallbackEndpoint) if the primary server returns5xxor times out.
- Submits to your primary FormFork server (
- Multipart & JSON Support: Pass the native DOM
@submit="handleSubmit"event, anHTMLFormElement, aFormDataobject (with file attachments), or a reactive JSON state object. - Cryptographic Offline Authorization: Supports
embedToken(X-FormFork-Token) and stateless HMACfallbackTicket(X-FormFork-Ticket) so your fallback server can verify the request even when the main FormFork server is offline.
Installation
# npm
npm install @formforkio/vue
# pnpm
pnpm add @formforkio/vue
# yarn
yarn add @formforkio/vue
# bun
bun add @formforkio/vueQuick Start (Vue 3 / Nuxt 3 <script setup>)
1. Binding to a Native <form> (Supports File Uploads & Honeypot)
<script setup lang="ts">
import { reactive } from 'vue';
import { useFormFork } from '@formforkio/vue';
const { state: ffState, handleSubmit, reset } = useFormFork('form-support-ticket', {
endpointHost: 'https://forms.yourdomain.com',
fallbackEndpoint: 'https://fallback.yourdomain.com/index.php?formId=form-support-ticket',
embedToken: 'ff_pub_live_98a7bc65d4e3f210',
timeoutMs: 5000,
});
// Optional: wrap in Vue reactive() if mutating nested properties in template
const formState = reactive(ffState);
</script>
<template>
<div v-if="formState.succeeded" class="rounded-xl border border-emerald-200 bg-emerald-50 p-6">
<h3 class="text-lg font-semibold text-emerald-900">Support Request Received</h3>
<p class="mt-1 text-sm text-emerald-700">
<span v-if="formState.queuedViaFallback">
Your request was securely spooled by our high-availability fallback node (ID: {{ formState.submissionId }}).
</span>
<span v-else>
Ticket #{{ formState.submissionId }} has been created.
</span>
</p>
<button
type="button"
class="mt-4 text-sm font-medium text-emerald-800 underline"
@click="reset"
>
Submit another ticket
</button>
</div>
<form v-else class="space-y-4" @submit="handleSubmit">
<!-- Honeypot trap for bots -->
<input
type="text"
name="_gotcha"
tabindex="-1"
autocomplete="off"
style="position: absolute; left: -9999px; opacity: 0"
/>
<div>
<label for="email" class="block text-sm font-medium">Email</label>
<input
id="email"
name="email"
type="email"
required
class="mt-1 w-full rounded-md border px-3 py-2"
/>
</div>
<div>
<label for="subject" class="block text-sm font-medium">Subject</label>
<input
id="subject"
name="subject"
type="text"
required
class="mt-1 w-full rounded-md border px-3 py-2"
/>
</div>
<div>
<label for="screenshot" class="block text-sm font-medium">Screenshot (Optional)</label>
<input id="screenshot" name="screenshot" type="file" accept="image/*,.pdf" />
</div>
<p v-if="formState.errorMessage" class="text-sm text-red-600" role="alert">
{{ formState.errorMessage }}
</p>
<button
type="submit"
:disabled="formState.submitting"
class="rounded-lg bg-slate-900 px-5 py-2.5 text-sm font-semibold text-white disabled:opacity-50"
>
{{ formState.submitting ? 'Submitting...' : 'Submit Ticket' }}
</button>
</form>
</template>2. Submitting Reactive v-model State Programmatically
You can also pass a plain JavaScript object directly to handleSubmit:
<script setup lang="ts">
import { ref, reactive } from 'vue';
import { useFormFork } from '@formforkio/vue';
const email = ref('');
const plan = ref('pro');
const { state, handleSubmit } = useFormFork('Waitlist Signup', {
endpointHost: 'https://forms.yourdomain.com',
embedToken: 'ff_pub_live_98a7bc65d4e3f210',
});
const ui = reactive(state);
async function onSubmitCustom() {
await handleSubmit({
email: email.value,
plan: plan.value,
referrer: document.referrer,
});
}
</script>API Reference
useFormFork(formIdOrName, options?)
Returns { state, handleSubmit, reset }.
VueFormForkOptions
| Option | Type | Default | Description |
| :--- | :--- | :--- | :--- |
| embedToken | string | undefined | Public embed token (ff_pub_...) sent in X-FormFork-Token. |
| fallbackTicket | string | undefined | Stateless HMAC ticket (X-FormFork-Ticket) for offline fallback verification. |
| endpointHost | string | 'https://formfork.io' | Primary FormFork server base URL. |
| fallbackEndpoint | string | 'https://fallback.formfork.io/index.php' | Store-and-Forward fallback node URL. |
| timeoutMs | number | 6000 | Primary request timeout in ms before failing over to fallbackEndpoint. |
| enableOfflineOutbox | boolean | undefined | Optional flag for offline outbox mode. |
VueFormForkState
| Property | Type | Description |
| :--- | :--- | :--- |
| submitting | boolean | true while request is in flight. |
| succeeded | boolean | true when accepted by primary or Store-and-Forward fallback server. |
| queuedViaFallback | boolean | true if spooled on the fallback node while primary was unreachable. |
| queuedOffline | boolean | true if queued locally. |
| errorMessage | string \| null | Validation or network error message if submission failed. |
| submissionId | string \| null | Unique submission or spool ID. |
License
MIT
