@hookieai/forms
v0.1.0
Published
Submit HTML forms to Hookie: a zero-dependency browser client with idempotent retries, readable field errors, progressive enhancement and a React hook.
Maintainers
Readme
@hookieai/forms
Submit HTML forms (contact, newsletter, waitlist, survey) to a Hookie endpoint. No dependencies, no backend: the endpoint's public URL is the only configuration.
<form id="contact" action="https://app.hookie.ai/acme/site/aBcXyz…" method="post">
<input name="email" type="email" required />
<textarea name="message" required></textarea>
<input name="_gotcha" tabindex="-1" autocomplete="off" style="position:absolute;left:-9999px" aria-hidden="true" />
<button>Send</button>
</form>
<script type="module">
import { enhanceForm } from "https://cdn.jsdelivr.net/npm/@hookieai/forms/index.mjs";
enhanceForm(document.getElementById("contact"), { onSuccess: () => alert("Thanks!") });
</script>Without JavaScript the form still posts natively and Hookie shows its thank-you page (or redirects to the endpoint's redirect_url). With JavaScript, enhanceForm submits with fetch(), so the endpoint must list the page's origin in its cors_origins.
API
submitForm(url, data, opts?)→{ ok, submissionId }or{ ok: false, status, error, fieldErrors?, reason?, retryAfter? }. OneIdempotency-Keyper submission, reused on retry, so a double click stores one event.enhanceForm(form, { onSuccess, onError, redirect, reset })→ an unsubscribe function.useHookieForm(url)from@hookieai/forms/react→{ submit, status, fieldErrors, error, reset }.defineFields([...] as const)andFieldsOf<typeof fields>type a payload from the endpoint'sform_fields.
The fastest way to set all of this up is npx @hookieai/cli forms init contact --to slack --origin https://example.com --json, which creates the endpoint and writes the form. Guide: https://docs.hookie.ai/forms
For AI agents
A coding agent can do all of this with no person involved: it registers itself on the Free plan (1,000 events a month, no card), then runs the command above. The machine-readable guide is https://hookie.ai/llms.txt and the signup steps are on https://hookie.ai/agents.
