Forms are the primary way you’ll collect information from your users. In this tutorial, we’ll build a complete contact form that includes real-time validation to ensure the data is correct before it’s submitted. We will cover:
- Creating a Zod Schema to define our data rules.
- Building the Form UI with input fields and a submit button.
- Linking the Form to our Zod Schema.
- Creating a Workflow to handle the submission and show feedback.
Part 1: Define the Rules with a Zod Schema
First, we need to create the “rulebook” for our form data.1
1. Navigate to Zod Schemas
Go to the Data tab in the top navigation bar, then select the “Zod Schemas” sub-tab.
2
2. Create the Schema
Create a new schema and name it
ContactFormSchema.3
3. Add and Configure Fields
Add the following fields and validation rules to your schema. This will define the structure and requirements for our form.
| Field Name | Data Type | Key Validation Rules | Error Message Example |
|---|---|---|---|
name | Text | Required, Minimum length: 2 | ”Name must be at least 2 characters.” |
email | Email | Required | ”Please enter a valid email address.” |
message | Text | Required, Minimum length: 10 | ”Message must be 10+ characters.” |
Part 2: Build the Form UI
Now, let’s create the visual form on our page.- Add a Form Element: From the Elements tab, drag a Form element onto your canvas. This will act as the container for our inputs.
- Add Input Fields and Error Text: For each field in our schema (
name,email,message), you will add two elements inside the Form container:- An Input element where the user will type.
- A Text element placed directly below the input. This is where the validation error message will appear. You can style it to be red to make it stand out.
- Add a Submit Button: Drag a Button inside the Form container. In its properties, set its
typetoSubmit. This is a special type that tells the button to trigger the form’s own workflow. - Add a Text Element for Feedback: Place a Text element somewhere near the form. We will use this to show a “Thank you!” message.
Part 3: Link the Form to the Schema
This is the magic step where we connect our UI to our rules.1
1. Select the Form Element
Click on the main Form element on your canvas (the container).
2
2. Link the Schema
In the Properties Panel on the right, find the property for
Schema.
Click the dropdown and select your newly created ContactFormSchema.3
3. Link Each Input and Error Text
Now, we need to tell the form how each input and error message corresponds to a rule in our schema.
-
For the “Name” Input:
- Select the
nameInput element. In its properties, set theNametoname. - Select the
nameText element below it. In its properties, find theForm error messageand select thenamefield from the schema.
- Select the
-
For the “Email” Input:
- Select the
emailInput element and set itsNametoemail. - Select the
emailText element and set itsForm error messageto theemailfield.
- Select the
-
For the “Message” Input: 1. Select the
messageInput element and set itsNametomessage. 2. Select themessageText element and set itsForm error messageto themessagefield.
Part 4: Create the Submission Workflow
Finally, we need to tell the form what to do when the user clicks the “Submit” button or press the “Enter” key and the data is valid.- Select the Form Element: Select the main Form container again.
- Open the Logic Tab: Go to the Logic tab in the top navigation bar. Because it’s a form, it has a special trigger called “On Submit”. This workflow will only run if all the data passes the schema’s validation rules.
- Add Your Actions: In the “On Submit” workflow, you can now add the actions to process the valid data. For this tutorial, let’s do two things:
- Add a “Create new data” action to save the form’s data to a
SubmissionsData Table. You can access the form’s data using theData Submitted from Formvariable. - Add a “Show / Hide element” action to display the “Thank you!” message you created earlier.
- Add a “Create new data” action to save the form’s data to a