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

Example

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:

Form input methods

The following methods apply to form input elements:

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
Built with