Skip to main content
For developers who want to create custom form experiences using Lantern’s form builder, this guide shows you how to implement forms using Lantern’s API endpoints and integrate them seamlessly into your Shopify theme.

Prerequisites

Before building custom forms, ensure you have:
  • Forms functionality enabled in your Lantern app
  • A form created in the Lantern admin with your desired fields
  • Basic knowledge of JavaScript, HTML, and Liquid templating
  • Access to your theme’s code

How Lantern Forms Work

Lantern forms follow a simple workflow:
  1. Create a form in the Lantern admin with your desired fields
  2. Build an HTML form in your Shopify theme that matches the form structure
  3. Submit form data via Lantern’s app proxy endpoint
  4. Handle responses and display success/error messages
Forms can include various field types including text inputs, select dropdowns, checkboxes, and can update both customer profile fields and custom Lantern properties.

API Access

Lantern forms can be accessed in multiple ways:

Direct API Access

Use your store’s direct URL format for form submissions and configuration:
  • GET /a/lantern/form/{handle} — retrieve form configuration (details)
  • POST /a/lantern/form/{handle} — submit form data (details)

Shopify Metaobjects

Access form configuration through Shopify’s native metaobject system using Liquid templates or GraphQL. This is ideal for theme developers who want to avoid external API calls and leverage Shopify’s caching.

Accessing Forms Through Shopify Metaobjects

Lantern automatically creates Shopify metaobjects for each form, allowing you to access form configuration directly through Shopify’s native APIs and Liquid templating. This is particularly useful for theme developers who want to access form data without making external API calls.

Metaobject Structure

Each form is stored as a metaobject of type lantern_forms with the following fields:
  • configuration: JSON field containing the complete form schema (same as API response)
  • name: The display name of the form

Accessing in Liquid Templates

You can access form configuration directly in your Liquid templates:

Benefits of Metaobject Access

Using metaobjects provides several advantages:
  • No external API calls: Access form configuration directly through Shopify’s native systems
  • Caching: Leverage Shopify’s caching for better performance
  • Theme integration: Seamlessly integrate with existing Liquid workflows
  • Real-time updates: Changes to forms are automatically reflected in metaobjects

Getting Form Configuration

Fetching Form Schema

You can also fetch the form configuration and field definitions using the GET endpoint:

Form Structure

The form configuration returns the following structure:

Submitting a Form

You can submit forms using a POST request the provided app proxy endpoint:

Field Types and Validation

Supported Field Types

Lantern forms support various field types:
  • Text: Text-based inputs with various input types (TextInput, PhoneInput, etc.)
  • Textarea: For longer text content
  • SingleChoice: Single selection from predefined options (Select dropdown or Radio buttons)
  • Boolean: Boolean values (Checkbox)
  • Number: Numeric inputs
  • Date: Date selection inputs

Profile vs. Property Fields

Lantern forms can update two types of data:
  1. Profile fields (prefix: profile:): Update Shopify customer profile data
    • profile:email - Customer email
    • profile:first-name - Customer first name
    • profile:last-name - Customer last name
    • profile:phone - Customer phone number
    • profile:birth-date - Customer birth date (YYYY-MM-DD format)
    • profile:accepts-marketing - Marketing consent (boolean)
    • profile:accepts-sms-marketing - SMS marketing consent (boolean)
  2. Attribute fields (prefix: attribute:): Update custom Lantern attributes. Examples:
    • attribute:other-interests - Array of interests (e.g., [‘music’, ‘sports’])
    • attribute:where-did-you-here-about-us - Custom attribute for referral source
    • attribute:would-you-recommend-us - Custom attribute for recommendation

Validation

Lantern performs comprehensive server-side validation on all form submissions. When validation fails, the API returns a 422 Unprocessable Entity status with detailed error information.

Validation Types

Lantern validates several aspects of form submissions:
  1. Required Fields: Ensures all fields marked as required: true have values
  2. Data Types: Validates that values match the expected valueType (String, Number, Boolean, Date)
  3. Email Format: Validates email addresses for profile email fields
  4. Phone Format: Validates phone numbers for profile phone fields
  5. Date Format: Ensures dates are in valid ISO format (YYYY-MM-DD)
  6. Choice Values: Ensures selected values exist in the field’s choice options

Error Response Format

When validation fails, you’ll receive a response like this:

Common Validation Scenarios

Missing Required Fields:
Invalid Email Format:
Invalid Choice Value:
Type Mismatch:

Handling Validation Errors

Process validation errors in your form submission handler:

Troubleshooting

Common Issues

  • CORS errors: Ensure requests are made from the same domain or configure CORS properly
  • 404 Not Found: Verify the form handle exists and is associated with the correct shop
  • 422 Validation Error: Check that required fields are provided and data types match
  • Form not submitting: Ensure the form action points to the correct endpoint