API Reference
Installation
Section titled “Installation”npm install formtress-jsCurrent version: 0.1.17
submitForm(options)
Section titled “submitForm(options)”Submits form data to the Formtress endpoint.
import { submitForm } from 'formtress-js'
const result = await submitForm({ formId: 'your-form-id', data: new FormData(formElement),})Parameters
Section titled “Parameters”| Name | Type | Required | Description |
|---|---|---|---|
options | object | Yes | Submission options. |
options.formId | string | Yes | The Form ID from your Formtress dashboard. |
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}| 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. |
Webflow script
Section titled “Webflow script”The Webflow script is a pre-built integration that requires no JavaScript on your part.
CDN URL
Section titled “CDN URL”https://cdn.jsdelivr.net/npm/formtress-js@0.1.17/dist/js/webflow.js
Behavior
Section titled “Behavior”- On
DOMContentLoaded, finds all<form>elements with adata-ftattribute. - Attaches a submit handler to each form.
- Prevents the default form action.
- Collects form data and sends it to the Formtress endpoint.
- On success: triggers Webflow’s native success state.
- On error: triggers Webflow’s error state and updates any
data-ft-errorelement.
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.1.17/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>