API Reference
Installation
Section titled “Installation”npm install formtress-jsCurrent version: 0.2.1
submitForm(options)
Section titled “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
Section titled “Parameters”| Name | Type | Required | Description |
|---|---|---|---|
options | object | Yes | Submission options. |
options.url | string | Yes | The form’s submit URL (https://app.formtress.com/api/f/your-form-id). Typically read from form.action. |
options.data | FormData | Yes | A FormData instance containing the fields to submit. |
Return value
Section titled “Return value”Returns Promise<SubmitResult>.
interface SubmitResult { ok: boolean message?: string status?: number}| Field | Type | Description |
|---|---|---|
ok | boolean | true if the submission was accepted and passed validation. |
message | string | undefined | Error message from the server. Only present when ok is false. |
status | number | undefined | HTTP status code from the server. |
Webflow script
Section titled “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
Section titled “CDN URL”https://cdn.jsdelivr.net/npm/formtress-js@0.2.1/dist/js/webflow.js
Behavior
Section titled “Behavior”- On
DOMContentLoaded, finds all<form>elements whoseactionpoints to the Formtress submit endpoint. - Attaches a submit handler to each form.
- Intercepts and prevents the default form submission.
- Collects form data and sends it to the form’s
actionURL viafetch. - On success: triggers Webflow’s native success state.
- On error: triggers Webflow’s error state and updates any
data-ft-errorelement. - Without the script: the form submits normally via standard HTML — spam protection still runs server-side.
Pinning a version
Section titled “Pinning a version”Always pin to a specific version in production:
<script src="https://cdn.jsdelivr.net/npm/formtress-js@0.2.1/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>