Collecting submissions
A page needs only the public form_id. API keys never go into browser code.
| Way | Snippet | Success message and redirect |
|---|---|---|
| Hosted link | https://formhaus.cc/Xk3d9QpL2a | Yes |
| Embed | <script src="https://formhaus.cc/embed.js" data-form="Xk3d9QpL2a" async></script> | Yes |
| Iframe | <iframe src="https://formhaus.cc/Xk3d9QpL2a?embed=1" ...></iframe> | Success message only |
FormhausForm | <FormhausForm id="Xk3d9QpL2a" /> | Yes, unless you pass success, which also skips the redirect |
| POST JSON | POST https://api.formhaus.cc/f/Xk3d9QpL2a | Your code |
Hosted link
The page renders the latest version with the default fields and a "Made with Formhaus" footer. ?theme=light or ?theme=dark sets the theme. Unclaimed forms show a notice that an AI agent published the form and can read the responses, and noindex. The footer links to the Terms, the Privacy Policy and Report abuse.
Test responses
Open form in the dashboard opens the hosted link with ?test=1. The page removes the parameter from the address, so the link in the address bar can be shared as is. Responses sent from that page are test responses. A page opened without the parameter, or reloaded after it was removed, sends normal responses.
A test response:
- is listed in the dashboard with a
Testbadge and has"test": truein the REST API; - is left out of the overview chart, the response statistics, timing, scale scores, the weekly summary and response milestones;
- is delivered as usual: the response email, webhook and integrations, so you can check them end to end;
- counts toward the monthly response limit, because any visitor can add
?test=1to a link; - is included in the CSV export.
Embed
The script inserts an iframe of the hosted page after itself and resizes it to the form height.
| Attribute | Value |
|---|---|
data-form | Required. form_id. |
data-theme | light or dark |
data-title | iframe title. Default Form. |
A redirect_url opens in the parent page.
Iframe
A plain iframe of the embed page, for sites that do not allow scripts. It renders like the script embed with a fixed height. The form scrolls inside the frame when it is taller.
<iframe src="https://formhaus.cc/Xk3d9QpL2a?embed=1" title="Contact us" width="100%" height="560" style="border:0" loading="lazy"></iframe>publish_form and the dashboard return it as iframe_snippet with height estimated from the form, between 400 and 900. Add &theme=light or &theme=dark to the src to set the theme. Change height to fit. A redirect_url is not followed: the frame shows the success message.
FormhausForm
FormhausForm loads the form from GET /f/{id}/form, renders it and posts submissions. It shows the form's success message, opens its redirect URL after a submission, and offers "Submit another response" when the form allows it. publish_form returns both files below as react_snippet and vue_snippet.
npm install @formhaus/react @formhaus/core
npm install @formhaus/vue @formhaus/coreimport { FormhausForm } from '@formhaus/react/cloud';
import '@formhaus/core/style.css';
export default function Page() {
return <FormhausForm id="Xk3d9QpL2a" />;
}<script setup lang="ts">
import { FormhausForm } from '@formhaus/vue/cloud';
import '@formhaus/core/style.css';
</script>
<template>
<FormhausForm id="Xk3d9QpL2a" />
</template>The React entry is a client component. In the Next.js App Router, import it from a server component page such as app/waitlist/page.tsx without a 'use client' directive. For Nuxt, save the Vue file under components/ or pages/.
Callbacks:
<FormhausForm id="Xk3d9QpL2a" onSuccess={(submission) => console.log(submission.id)} /><FormhausForm id="Xk3d9QpL2a" @success="(submission) => console.log(submission.id)" />| Prop | Description |
|---|---|
id | Required. form_id. |
apiBase | API origin. Default https://api.formhaus.dev. |
components | Custom field components, as in FormRenderer. |
onSuccess / @success | Called with { id, values } after a 201. |
onError | Called with a CloudError (status, code, errors) when loading or submitting fails. A network failure has status 0 and code "network". A request that gets no response within 15 seconds for the definition or 30 seconds for a submission has status 0 and code "timeout". |
initialForm | A form loaded on the server with fetchForm({ id }) from @formhaus/core/cloud. The component renders it without a request. |
draftStore | Keeps unsent answers across reloads. On by default with sessionDraftStore() from @formhaus/core/cloud, which keeps them in sessionStorage until the tab closes and at most 7 days, and leaves out password, file and hidden values. Pass false to turn drafts off, or your own DraftStore to keep them elsewhere. sessionDraftStore takes an options object: { maxAge, storage }. Values of custom field types are kept. |
draftExclude / draft-exclude | Field keys left out of the draft. A group key leaves out the whole group. |
fallback / #fallback | Shown while the definition loads. |
success / #success | Replaces the default message after a submission. |
Other FormRenderer props pass through. The error summary shows by default; pass errorSummary={false} (Vue: :error-summary="false") to hide it. A 422 maps errors onto fields and focuses the first one. Messages for keys the form does not render are listed in a notice above the form. Every other failure shows a short message in the same notice, which takes focus, with "Try again" for 429, 5xx, network failures and timeouts. Entered values stay. When the definition fails to load for one of these reasons or returns a body that is not JSON, the error has a "Try again" button that loads it again.
FormhausForm sends the version it rendered. If the form was republished and the values no longer pass, it loads the new version, keeps the answers whose field key and type still fit, marks dropped answers with "Please answer again." and asks the respondent to review and submit again.
POST JSON
https://api.formhaus.dev/f/{id} accepts the same requests. A country hidden field is filled only for submissions to api.formhaus.cc.
curl -X POST https://api.formhaus.cc/f/Xk3d9QpL2a \
-H 'Content-Type: application/json' \
-H 'Idempotency-Key: 5b0f6f1e-3c59-4a40-9a57-3c1d6d8f0f11' \
-d '{"values":{"email":"ada@example.com"},"skippedSteps":[]}'| Body field | Type |
|---|---|
values | Object, field key to value. Missing or null is {}. |
skippedSteps | Array of step ids. Honored only for steps with skip; their values are dropped. |
version | Optional integer, the definition version the form was rendered from. |
attribution | Optional object with utm_source, utm_medium, utm_campaign, utm_term and utm_content strings. Other keys are dropped, values are trimmed and cut to 100 characters. |
timing | Optional object, see Timing. |
order | Optional object, see Option order. |
The hosted page, embeds and FormhausForm (@formhaus/core 0.17 and later) send the UTM parameters of the page address as attribution. They are stored apart from values. Of the Referer header only the origin is stored, such as https://example.com.
Timing
The hosted page and embeds also send how long the respondent spent on each question:
{
"v": 1,
"totalMs": 95000,
"fields": { "email": { "activeMs": 12400, "firstMs": 2500, "changes": 18 } },
"steps": { "about": { "ms": 61000, "visits": 2 } }
}| Key | Value |
|---|---|
totalMs | Time from the first render to submit |
fields.<key>.activeMs | Time with focus inside the field. Each focus counts at most 30 minutes. |
fields.<key>.firstMs | Time from the field being shown to its first change. Left out when it never changed. |
fields.<key>.changes | Number of value changes |
steps.<id> | Time on the step (ms) and number of visits. Multi-step forms only. |
Times are milliseconds and leave out time while the tab is hidden. Fields the respondent never focused or changed are left out. Fields inside a repeater count under the repeater's key. A click on a checkbox or radio button counts as focus, also in browsers that do not focus them on click. Every number must be an integer from 0 to 86,400,000; otherwise the whole timing object is dropped and the submission is still saved. Keys that are not fields or steps of the latest version are dropped. Timing is not part of the idempotency check. Submissions from FormhausForm and direct API calls have no timing unless they send it.
Option order
On a field with randomize, the hosted page and embeds shuffle the options for each respondent and send the order they saw:
{ "order": { "tools": ["sketch", "figma", "other", "none"], "team.role": ["pm", "dev"] } }Keys are answered radio, select and multiselect fields with randomize. A field in a repeater uses group.field and has one order for all items. The order holds through Back, reloads and a restored draft in the same tab. "Submit another response" and a new tab start a new order.
An entry is stored only when it lists each static option value of that field in the validated version exactly once. Other entries, keys that are not randomized fields, fields with optionsFrom and fields in a matrix section are dropped, and the submission is still saved. The order is stored apart from values, is not part of the idempotency check and is not sent in webhooks.
| Status | Body |
|---|---|
201 | { "id": "<uuid>", "values": {...} }, the values as stored. With a matching ending, also "ending": { "successMessage": "..." } or "ending": { "redirectUrl": "..." }. |
400 | { "error": "malformed_body" } or { "error": "invalid_idempotency_key" } |
402 | { "error": "limit_reached" }: the form is unclaimed and has 100 submissions |
404 | { "error": "not_found" } |
409 | { "error": "paused" } or { "error": "idempotency_key_reused" } |
409 | { "error": "form_updated", "version": 4, "errors": {...} }, version is older than the latest and values fail the latest definition. Load the definition again and resubmit. With a valid body the submission is stored under the latest version. |
410 | { "error": "expired" } |
413 | { "error": "body_too_large" }, body or values over 64 KB |
415 | { "error": "unsupported_media_type" }, Content-Type is not application/json |
422 | { "error": "invalid", "errors": { "<field key>": "<message>" } } |
422 | { "error": "definition_refused", "details": ["<problem>"] }, the form has a pattern the server refuses to run. The owner fixes it and publishes again. |
426 | { "error": "client_outdated", "minCore": "<version>" }, the definition needs a newer @formhaus/core than the core query parameter |
429 | { "error": "rate_limited" } |
500 | { "error": "internal" } |
503 | { "error": "unavailable" }, validation timed out |
Every error body also has message, one sentence on how to fix the request. Branch on error, not on message.
Files
A file field takes the id of an upload. The hosted page, the embed and FormhausForm (@formhaus/core 0.18 and later) upload files for you. From your own client, upload each file first:
POST /f/{id}/uploadswith{"field": "cv", "name": "cv.pdf", "size": 48213}. The answer is201withid,url,method(PUT),headersandexpires_at.PUTthe file bytes tourlwithin 15 minutes, with the returnedContent-Typeheader. The storage refuses a body of another size or type.- Submit with the upload id as the value:
{"values": {"cv": "<id>"}}.
A file field with "multiple": true in a definition with "formatVersion": "1.7" or later takes a list of files. Upload each file with its own request, then submit the ids in order: {"values": {"docs": ["<id>", "<id>"]}}. One id on its own counts as a list of one. If a list allows more than 5 files or asks for more than 5, publishing returns a warning. The served definition then caps validation.maxLength and minLength at 5, so the hosted page and the embed stop at 5 and a list never asks for more than 5. When files of a list fail, the error names each file.
| Rule | Value |
|---|---|
| Size | Up to 10 MB per file |
| Files | Up to 5 file fields per form. A field takes one file, or up to 5 files when it has multiple, so a response holds at most 25 files and 250 MB. |
| Types | PDF, PNG, JPEG, WebP, GIF, TXT, CSV, DOCX, XLSX, by file name extension. The field's accept narrows the list. |
| Content | On submit the server checks the stored size and the first bytes of the file against its type |
| Upload requests | 30 per IP, then 1 every 10 seconds; 1000 per form per hour |
An upload request that breaks a rule gets 422 with {"error": "file_rejected", "code": "<reason>", "message": "..."}. code is file_type, file_too_large, empty_file, invalid_name or unknown_field. A submission whose file is missing, not uploaded, already used or of the wrong content gets 422 invalid with a message for that field. An upload that is not part of a response is deleted within about 3 hours.
Files are never public. Formhaus does not scan files for malware: owners download them as attachments, so a browser never opens them inline, but treat every file as untrusted.
Option values
select, radio and multiselect fields take the option value, not the label. A label that is not also a value fails with 422. multiselect takes an array of values.
{ "fields": [{ "key": "plan", "type": "select", "label": "Plan", "options": [{ "value": "pro", "label": "Pro plan" }] }] }{ "values": { "plan": "pro" } }Idempotency-Key
Optional header, 1 to 128 characters. Send the same key on every retry of one submission.
| Request | Result |
|---|---|
| New key | The submission is stored, 201 |
Same key, same values and skippedSteps | Replay: 201 with the first id, nothing new stored, also after the form is paused |
| Same key, different body | 409 idempotency_key_reused |
Keys are kept per form for 24 hours with a SHA-256 of the normalized body. FormhausForm and the hosted page send one per distinct body.
Rate limits
| Bucket | Burst | Refill |
|---|---|---|
| Per IP | 20 | 1 every 3 seconds |
| Per network | 100 | 1 every 0.6 seconds |
| Per form | 60 | 1 per second |
A network is the IPv6 /48 of the sender, or the IPv4 address itself. The buckets run before every other check, so 4xx responses and replays consume tokens. A 429 carries Retry-After in seconds.
CORS
Access-Control-Allow-Origin: *, or the request origin when the form has allowed domains. OPTIONS answers 204 with POST, OPTIONS and the headers Content-Type, Idempotency-Key. No cookies.
Allowed domains
A form with allowed domains loads and accepts submissions in a browser only on those websites. Set them in the dashboard under Settings > Allowed domains, or with allowed_domains in the REST API and update_form_settings.
example.commatches that host.*.example.commatchesexample.comand all its subdomains.- Enter domains only: no path or port. A leading
https://is removed. International names are stored in punycode. - Shared suffixes such as
github.io,vercel.apporco.ukare refused, with or without*.. Add your own subdomain, like*.you.github.io. localhost,*.localhost,127.0.0.1and[::1]on any port are always allowed and don't count toward the limit. So is the hosted page.- A form allows 3 entries. An empty list allows every website.
The definition, /form and POST /f/{id} check the Origin header. A request from another website gets 403 origin_not_allowed. A matching origin is echoed in Access-Control-Allow-Origin with Vary: Origin. The iframe embed is limited with frame-ancestors. Requests without Origin, such as from a server or curl, are allowed: this stops other websites from embedding the form, it is not authentication.
Anti-spam
The hosted page, the embed and FormhausForm send two extra body fields. _fh_hp is a hidden honeypot input. _fh_rt is the render token from the form response. A filled _fh_hp, an invalid _fh_rt, or less than 2 seconds between render and submit returns the usual 201 and stores nothing. Requests without _fh_rt skip the timing check. After a 409 form_updated refresh, they also send _fh_rt_first, the first render token the page received, and the server measures the time from that token.
Server-side validation
The server runs validateSubmission() from @formhaus/core against the latest version.
- Rules:
required,minLength,maxLength,min,max,pattern, and conditional visibility, steps and routes from the definition. - Types:
emailformat;numberaccepts numbers and numeric strings;checkboxandswitchneed booleans;select,radioandmultiselectvalues must be inoptions;scaleandratingtake a whole number in their range;dateisYYYY-MM-DD;datetimeis ISO 8601. Strings are at most 10,000 characters. - Unknown keys and values of hidden fields are dropped.
- Stored values are not altered. Zero-width, bidirectional and tag characters stay in the data; the dashboard shows them as
\u{XXXX}, andget_submissionsflags them withvalues_contain_hidden_characters. - Custom
validatorsand field actions run only in the browser. - A
patternthat runs over 50 ms fails the submission with422or503. - A
patternthatvalidateSubmission()refuses to run is refused at publish, and a form published with one before fails every submission with422 definition_refused. Someslow-patternpatterns, such as^\d+\.?\d*$, still run, and a value longer than 1000 characters fails them with the field's pattern error.
Endings
Endings replace the success message or the redirect for some respondents. Set them in Form settings → Endings, with endings in PATCH /v1/forms/{id}, or with update_form_settings.
[
{ "label": "Sales", "show": [{ "field": "topic", "eq": "sales" }], "redirect_url": "https://example.com/book-a-call" },
{ "label": "Big team", "showAny": [{ "field": "seats", "gte": 50 }, { "field": "plan", "eq": "enterprise" }], "message": "We'll write within a day." }
]- After each submission the server checks the endings in order against the stored values and returns the first match in
ending. Values of hidden fields are dropped before the check. showneeds every condition,showAnyneeds one. The conditions use the format of field conditions on the top-level fields of the latest version.- Each ending has
message(up to 500 characters) orredirect_url(http(s)), and an optionallabelup to 80 characters. Up to 10 endings with 10 conditions each. - With no match the form shows its success message or redirect.
- The hosted page, the embed and
FormhausFormshow the ending. A retry with the sameIdempotency-Keyreturns the ending of the first attempt. - A new version that drops a field used by an ending is rejected. Change the endings first.
- The response drawer shows which ending a respondent got.
WARNING
Hidden and read-only values come from the respondent, who can change them before sending. Do not trust them for prices, plans or permissions. Look those up on your server. This includes the values an ending condition reads.
Public form
GET https://api.formhaus.cc/f/{id}/form?core=<version> returns the latest version:
{
"definition": { "id": "contact", "title": "Contact", "submit": { "label": "Send" }, "fields": [] },
"version": 4,
"settings": { "successMessage": "Thanks!", "redirectUrl": "https://example.com/thanks", "allowAnother": false },
"renderToken": "..."
}core is the @formhaus/core version of the client. FormhausForm sends it on the GET and on the POST. CORS *. Unknown, paused and expired forms answer 404, 409 and 410 with { "error": "not_found" | "paused" | "expired", "message": "..." }.
GET /f/{id}/definition returns the bare definition with the version in the Formhaus-Version and Formhaus-Form-Version headers, for clients older than 0.11.
The _fh_* body keys and a top-level meta key are reserved.