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:- Create a form in the Lantern admin with your desired fields
- Build an HTML form in your Shopify theme that matches the form structure
- Submit form data via Lantern’s app proxy endpoint
- Handle responses and display success/error messages
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 typelantern_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:-
Profile fields (prefix:
profile:): Update Shopify customer profile dataprofile:email- Customer emailprofile:first-name- Customer first nameprofile:last-name- Customer last nameprofile:phone- Customer phone numberprofile:birth-date- Customer birth date (YYYY-MM-DD format)profile:accepts-marketing- Marketing consent (boolean)profile:accepts-sms-marketing- SMS marketing consent (boolean)
-
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 sourceattribute: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 a422 Unprocessable Entity status with detailed error information.
Validation Types
Lantern validates several aspects of form submissions:- Required Fields: Ensures all fields marked as
required: truehave values - Data Types: Validates that values match the expected
valueType(String, Number, Boolean, Date) - Email Format: Validates email addresses for profile email fields
- Phone Format: Validates phone numbers for profile phone fields
- Date Format: Ensures dates are in valid ISO format (YYYY-MM-DD)
- 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: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