esc

Type to search the documentation. ↑↓ to move, ↵ to open.

On this page

Reference

API Reference

Complete reference for the @formtress/js and @formtress/server packages.


Installation

Terminal window
npm install @formtress/js

Current version: 1.0.0

submitForm(options)

Submits form data to the Formtress endpoint.

import { submitForm } from '@formtress/js'
const result = await submitForm({
url: 'https://app.formtress.com/api/f/your-form-id',
data: new FormData(formElement),
})

Parameters

NameTypeRequiredDescription
optionsobjectYesSubmission options.
options.urlstringYesThe form’s submit URL (https://app.formtress.com/api/f/your-form-id). Typically read from form.action.
options.dataFormDataYesA FormData instance containing the fields to submit.

Return value

Returns Promise<SubmitResult>.

interface SubmitResult {
ok: boolean
message?: string
status?: number
}
FieldTypeDescription
okbooleantrue if the submission was accepted and passed validation.
messagestring | undefinedError message from the server. Only present when ok is false.
statusnumber | undefinedHTTP status code from the server.

Multi-value fields

FormData natively supports multi-value fields - checkbox groups, <select multiple>, etc. Every selected value is submitted and stored comma-joined (e.g. "Web,Design"), so no special handling is needed on your side.

Webflow script

The Webflow script progressively enhances standard HTML forms that submit directly to Formtress. Forms work without JavaScript; the script adds Webflow’s native success/error states and loading text support.

CDN URL

https://cdn.jsdelivr.net/npm/@formtress/js@1.0.0/dist/js/webflow.js

Behavior

  1. On DOMContentLoaded, finds all <form> elements whose action points to the Formtress submit endpoint.
  2. Attaches a submit handler to each form.
  3. Intercepts and prevents the default form submission.
  4. Collects form data and sends it to the form’s action URL via fetch.
  5. On success: triggers Webflow’s native success state.
  6. On error: triggers Webflow’s error state and updates any data-ft-error element.
  7. Without the script: the form submits normally via standard HTML, and spam protection still runs server-side.

Pinning a version

Always pin to a specific version in production:

<script src="https://cdn.jsdelivr.net/npm/@formtress/js@1.0.0/dist/js/webflow.js"></script>

To get the latest version automatically (not recommended for production):

<script src="https://cdn.jsdelivr.net/npm/@formtress/js@latest/dist/js/webflow.js"></script>

@formtress/server

Terminal window
npm install @formtress/server

Current version: 0.1.0

POST /public/api/v1/filter

The raw HTTP endpoint behind @formtress/server. No data is stored; this endpoint only returns a spam score.

Headers

HeaderRequiredDescription
AuthorizationYesBearer ftk_<your-api-key>
Content-TypeYesapplication/json

Request body

{
"ip": "1.2.3.4",
"headers": Object.fromEntries(request.headers),
"fields": [
{ "name": "email", "value": "test@gmail.com", "type": "email" },
{ "name": "message", "value": "Hello world", "type": "text" }
],
"blockFreeEmailProviders": true
}
FieldTypeRequiredDescription
ipstringYesEnd-user’s IP address (used for rate limiting).
headersRecord<string, string>YesForwarded request headers from the end-user’s browser.
fieldsArray<{ name, value, type }>NoField values for content-level spam detection.
blockFreeEmailProvidersbooleanNoFlag free email providers (e.g. gmail.com) as spam. Defaults to false.

Response (200 OK)

{
"isSpam": true,
"score": 0.85,
"rateLimited": false,
"fieldErrors": {
"email": "spam detected"
}
}
FieldTypeDescription
isSpambooleanWhether the submission was detected as spam.
scorenumberSpam confidence score (0–1).
rateLimitedbooleanWhether the end-user was rate limited.
fieldErrorsRecord<string, string>?Per-field spam errors (only present if fields were flagged).

Response (401 Unauthorized)

{ "error": "Invalid or missing API key" }

Response (400 Bad Request)

{
"error": "Invalid request body",
"issues": { ... }
}

Endpoint URL

https://app.formtress.com/public/api/v1/filter