For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Resources
Get started
ReferenceGuidesExamplesChangelog
ReferenceGuidesExamplesChangelog
  • Designer API
    • Introduction
    • Getting Started
    • Webflow CLI
    • Error Handling
    • App Modes
  • Elements
    • Creating & Retrieving Elements
    • Element Properties & Methods
    • Element Types & Methods
      • Element Presets
      • DOM Elements
      • Strings
      • Components
      • Slots
      • Headings
      • Images
      • Links
      • Forms
        • Get Form Name
        • Set Form Name
        • Get Form Settings
        • Set Form Settings
        • Form Inputs
  • Styles
    • Managing Style Properties
    • Managing Variable Modes
  • Components
  • Variables & Collections
    • Variable Collections
    • Variables
    • Variable Modes
  • Assets
  • Pages & Folders
  • Utilities
    • User Events & Notifications
    • App Intents & Connections
  • Additional Resources
    • API Playground
    • FAQs
LogoLogo
Resources
Get started
On this page
  • Creating a form
  • Form structure
  • Form inputs
  • Form labels
  • Methods
  • Form element methods
  • Form input methods
  • Properties
ElementsElement Types & Methods

Forms

Was this page helpful?
Previous

Get Form Name

Next
Built with

Webflow Forms enable users to capture and collect information from visitors on a site.

Creating a form

Use the FormForm element preset to create a form.

1// Get the currently selected element
2let el = await Webflow.getSelectedElement();
3
4// Create a form element
5let form = await el.after(webflow.elementPresets.FormForm);

When you create a form using the FormForm preset, it automatically generates a complete form structure with default form fields, as well as a success and error message.

Form Element Preset

Form structure

A Webflow form consists of several nested elements that work together:

ElementDescriptionParent Element
FormWrapperThe outermost container element that encapsulates the entire form structure
FormFormThe main form element containing all form fields and inputsFormWrapper
FormSuccessMessageThe success message after successful form submissionFormWrapper
FormErrorMessageThe error message if form submission failsFormWrapper
FormInputAn individual form field.
FormBlockLabelThe label for a FormInputFormInput
FormButtonThe submit button for the formFormForm

Form inputs

Form inputs are the individual fields that collect user information. It’s recommended to create a wrapper to contain each input and it’s corresponding label.

You can create form inputs using the following element presets:

  • FormTextInput
  • FormTextarea
  • FormSelect
  • FormCheckboxInput
  • FormRadioInput

It’s a best practice to wrap each input and its corresponding label (e.g. FormBlockLabel) in a container element, such as a DivBlock, to keep them organized.

Example

Inline
1// Get the currently selected element
2let el = await Webflow.getSelectedElement();
3
4// Create a form element
5let formWrapper = await el.after(webflow.elementPresets.FormForm);
6
7// Add a text input with a label
8let formWrapperChildren = await formWrapper.getChildren(); // Get the form element
9let formInputs = formWrapperChildren[0]; // Get the form element
10let inputWrapper = await formInputs.append(webflow.elementPresets.DOMElement); // Create a wrapper for the input and label
11let label = await inputWrapper.append(webflow.elementPresets.FormBlockLabel); // Create a label
12let input = await inputWrapper.append(webflow.elementPresets.FormTextInput); // Create a text input

Form labels

Each input should have a label that describes the information it collects. Create a label using the FormBlockLabel element preset to label each input.

Methods

Form element methods

The methods documented below apply specifically to the FormForm and FormWrapper elements.

The Form Element supports the following specific methods:

Get form name

Retrieves the name of the form.

Set form name

Sets the name of the form.

Get form settings

Retrieves the settings of the form.

Set form settings

Sets the settings of the form.

Form input methods

The following methods apply to form input elements:

Get required status

Retrieves the required status of a form input.

Set required status

Sets the required status of a form input.

Get input name

Retrieves the name of the input field.

Set input name

Sets the name of the input field.

Get input type

Retrieves the type of the input field.

Only supported by FormTextInput.

Set input type

Sets the type of the input field.

Only supported by FormTextInput.

Properties

PropertyDescriptionTypeExample
idThe unique identifier for the form.object{component: "64c813...", element: "5edf8e59-71f9..."}
typeThe type of the element.string"FormForm" || "FormWrapper
childrenIndicates if the element can contain child elements.booleantrue
customAttributesIndicates if the element can contain custom attributes.booleantrue
stylesIndicates if the element can contain styles.booleantrue
textContentIndicates if the element can contain text content.booleanfalse
appConnectionsIndicates if the element can contain app connections.booleantrue