Fields

The FormField model, its 27+ field types, validation, conditional logic and dynamic option sources.

Overview

The FormField model represents an individual form input. Polyform ships with 27+ field types, from simple text inputs to matrix grids and repeatable field groups. Fields support validation, conditional visibility, nesting and both static and dynamic option sources.

Field Types

The FieldType enum defines 27+ string-backed types, each with behavior methods:

Core Properties

PropertyTypeDescription
typeFieldTypeField type from FieldType enum
keystringUnique identifier for form data (unique per form)
labelstringDisplay label shown to users
descriptionstring|nullHelp text or instructions
placeholderstring|nullPlaceholder text for inputs
default_valuemixedDefault value when rendering empty form
validation_rulesarrayLaravel validation rules
conditionsarrayConditional display logic
settingsarrayField-specific configuration
is_requiredboolWhether field is required
sort_orderintDisplay order within form or step

Creating Fields

The FormBuilder has convenience methods for every field type or you can create fields directly through relationships:

app/Http/Controllers/FormController.php

Field Settings

Each field type has its own settings stored as JSON. Here are some common examples:

Conditional Logic

Fields can be shown or hidden based on other field values:

Conditions are evaluated on the frontend via the useFieldConditions composable and on the backend during validation.

Validation Rules

Fields store Laravel validation rules that run during submission:

The FieldValidatorFactory maps each FieldType to its validator class. You can register your own validators through the factory.

Option Sources

Select, radio, checkbox and similar fields can pull options from multiple sources:

  • Static options - Stored as FormFieldOption records
  • Enum options - Loaded from PHP enums via cases()
  • Model options - Queried from Eloquent models
  • Resolver options - Generated by custom resolver classes

Relationships

  • form - BelongsTo Form (parent form)
  • step - BelongsTo FormStep (parent step for multi-step forms)
  • parent - BelongsTo FormField (parent field for nested structures)
  • children - HasMany FormField (child fields for repeaters)
  • options - HasMany FormFieldOption (static options)

Nested Field Structures

Repeater fields can contain nested child fields for more complex data:

The frontend PolyformRenderer handles nested field rendering and validation automatically using provide/inject.

Computed Attributes

  • has_dynamic_options - Whether options are loaded dynamically
  • resolved_settings - Merged field type defaults with custom settings

Extensibility

You can register custom field validators, option resolvers and field types through the package config and service provider bindings.