Form Templates

Learn how to create reusable form templates, clone forms from templates and manage a template library.

Overview

The FormTemplate model enables creating reusable form blueprints. Templates store form structure, fields, steps and settings as JSON schema, allowing you to quickly clone forms without rebuilding from scratch. This is ideal for standardized surveys, applications or recurring forms.

Core Properties

PropertyTypeDescription
namestringTemplate name (e.g., "Customer Feedback Survey")
descriptionstring|nullOptional description of template purpose
schemaarrayJSON schema containing form structure, fields, and steps
is_activeboolWhether template is available for cloning
metadataarrayAdditional data (category, tags, preview image, etc.)

Creating Templates

Create templates from existing forms using the CreateTemplateFromForm action:

app/Http/Controllers/TemplateController.php

Schema Structure

Templates store form data as structured JSON:

The schema includes all configuration needed to recreate the form, including conditional logic, validation rules and field relationships.

Cloning Forms from Templates

Use the Polyform facade to clone forms from templates:

app/Http/Controllers/FormController.php

Listing Templates

Use the is_active flag to control which templates are visible in template libraries or UI pickers.

Updating Templates

Updating a template does not affect existing forms cloned from it. Templates are version snapshots.

Template Metadata

Store additional information in the metadata JSON column:

Metadata enables categorization, search filtering, usage tracking and custom UI rendering.

FormBuilder Workflow

Build forms with the fluent builder, then convert to templates:

Complete Workflow

  1. Design and test form structure
  2. Create template from validated form
  3. Clone template for new instances
  4. Customize cloned forms as needed
  5. Update template when improvements are made

Seeding Templates

Populate your template library via database seeders:

database/seeders/FormTemplateSeeder.php

Seeding templates ensures consistent form structures across environments and simplifies onboarding.

Schema Validation

Common Use Cases

  • Recurring Surveys - Quarterly employee feedback, annual reviews
  • Application Forms - Job applications, grant requests, membership forms
  • Multi-Tenant SaaS - Standardized forms deployed per customer
  • Industry Templates - Healthcare intake, legal questionnaires, insurance claims
  • A/B Testing - Clone template, modify fields, compare submission rates

Best Practices

  • Test forms thoroughly before creating templates
  • Use descriptive names and detailed descriptions
  • Categorize templates with metadata tags
  • Version templates by including version number in metadata
  • Set is_active to false for deprecated templates
  • Track usage via metadata to identify popular templates
  • Regularly audit and update templates based on feedback

Extensibility

Templates are simple JSON storage and can be extended with:

  • Custom schema transformations during cloning
  • Template versioning systems
  • Import/export functionality for sharing across apps
  • Template marketplace features