Create a Default Form in Beefree SDK

Learn how to configure a default form in Beefree SDK that users can drag and drop onto the design stage, complete with pre-defined fields and validation.

Why Use Default Forms?

When building email campaigns, forms are essential for collecting user data like newsletter signups, survey responses, or contact information. Email recipients are typically led to these forms by clicking on a CTA (call-to-action) within the email that redirects to a landing page with the form within it. In Beefree SDK, forms can be built in both the page and popup builders. Instead of making your end users build forms from scratch every time they want to embed one within their page or popup design, you can pre-configure a default form with common field types and layouts. This default form will appear each time your end users drag and drop the Form block onto the stage for their page or popup design. Having a default form saves your end users time, and ensures consistency across content assets for their email campaigns.

With Beefree SDK's defaultForm configuration, you can:

  1. Pre-define common form structures (contact forms, surveys, registrations)

  2. Set up field validation rules (required fields, input types, placeholders)

  3. Enable drag-and-drop functionality so users can easily add forms to their designs

  4. Configure form behavior with custom handlers for save, submit, and change events

Project Map: Where to Look in the Sample Project

This recipe is based on the beefree-sdk-form-block-demo GitHub project. Clone it, then explore these key files:

File
Purpose
What You'll Learn

Single default form implementation

How to configure beeConfig.defaultForm with a complete form structure

Node.js authentication proxy

How to securely authenticate with Beefree SDK using LoginV2

Email template structure

How forms integrate with existing email designs

Multiple form library

How to implement form selection via content dialogs

Note: Use this working project and its core concepts to implement default forms in your host application.

Data Flow Diagram

Here's how the default form system works:

Why this flow? The defaultForm configuration provides the initial form structure, and Beefree SDK handles user interactions and form editing. The event handlers track form changes, and saves the Form as part of the design's JSON.

Step 1: Clone the Project

Clone the repository and install dependencies:

Create a .env file with your Beefree SDK credentials:

Step 2: The Proxy Server Setup

File to reference: proxy-server.js

The proxy server handles secure authentication with Beefree SDK:

Security Note: Keep your credentials server-side—never expose your Client Secret to the browser.

Step 3: Default Form Configuration

File to reference: default-form-example.html

The heart of the default form setup is the beeConfig.defaultForm object:

Step 4: Form Structure Breakdown

The defaultForm.structure object contains three main components:

Fields Definition

Each field is defined with:

  • type: Input type (text, select, radio, checkbox, etc.)

  • label: Display label for the field

  • attributes: HTML attributes (required, placeholder, min, max, etc.)

  • options: For select/radio/checkbox fields

  • canBeRemovedFromLayout: Whether users can remove this field

  • canBeModified: Whether users can edit field properties

Layout Array

A 2D array that defines field arrangement:

Form Attributes

Standard HTML form attributes:

Reference the full Form Validation Schema in GitHub.

Step 5: Event Handlers

File to reference: default-form-example.html (lines 307-329)

Configure event handlers to manage form interactions:

Step 6: Field Types and Validation

The default form supports various field types with built-in validation:

Step 7: Making the Form Draggable

Once configured, the default form automatically becomes available in the Beefree SDK editor:

  1. Form Block: Users can drag a Form block from the content panel

  2. Pre-populated: The form appears with your default structure

  3. Editable: Users can modify fields, layout, and styling

  4. Validation: Built-in validation based on your field definitions

Step 8: Running the Example

  1. Start the proxy server:

  1. Open default-form-example.html in your browser. You'll see:

    1. The Beefree SDK editor loads with authentication

    2. A pre-configured form is available in the form block

    3. Users can drag the form block onto the design stage

    4. The form includes all your predefined fields and validation

Advanced Configuration: Multiple Forms

If you are interested in providing your end users with a Form library of pre-existing forms they can choose from, reference the Create a Form Library in Beefree SDK documentation.

You can also reference the GitHub sample project's code to see how it is implemented: form-library-example.html

Learn More

Implementation Checklist

  • Set up proxy server for secure authentication

  • Configure defaultForm.structure with fields and layout

  • Add event handlers for form interactions

  • Define field validation with HTML5 attributes

  • Test drag-and-drop functionality in the editor

  • Handle form submissions in your application

Clone the example project, explore the default-form-example.html file, and adapt the defaultForm configuration to match your specific form requirements. The pre-configured form will then be available as a draggable block in your Beefree SDK editor.

Last updated

Was this helpful?