Forms

The Form model, its properties, relationships and how to create dynamic forms using the FormBuilder.

Overview

The Form model is the central piece of Polyform. It holds a collection of fields, optional steps, validation rules and settings. You can attach forms to any model through a polymorphic relationship, set submission limits and control their lifecycle with statuses.

Core Properties

PropertyTypeDescription
namestringDisplay name of the form
slugstringURL-friendly identifier (unique per formable)
descriptionstring|nullOptional form description or instructions
statusFormStatusCurrent status (DRAFT, PUBLISHED, CLOSED, ARCHIVED)
settingsarrayJSON configuration for behavior and UI options
opens_atdatetime|nullWhen the form opens for submissions
closes_atdatetime|nullWhen the form closes for submissions
max_submissionsint|nullMaximum number of submissions allowed
max_submissions_per_userint|nullPer-user submission limit

Settings Configuration

The settings property stores JSON configuration for form behavior:

SettingTypeDescription
show_progress_barboolDisplay progress indicator in multi-step forms
show_step_navigationboolShow next/previous buttons between steps
validate_on_step_changeboolValidate current step before allowing navigation
allow_save_draftboolEnable draft submission saving
require_authenticationboolRequire login to submit
send_confirmation_emailboolSend email after successful submission

FormStatus Enum

Forms use a string-backed enum with behavior methods that control submission acceptance and drive UI display.

app/Models/Survey.php

Relationships

Forms have several relationships to other models in the package.

Formable (Polymorphic)

Forms belong to a parent entity via a morphTo relationship. Add the HasPolyforms trait to your models:

app/Models/Survey.php

Other Relationships

  • fields - HasMany FormField (all fields in the form)
  • submissions - HasMany FormSubmission (all submission records)
  • steps - HasMany FormStep (multi-step form steps)
  • webhooks - HasMany FormWebhook (webhook endpoints)

Computed Attributes

  • is_open - Whether the form is currently accepting submissions
  • is_multi_step - Whether the form has multiple steps
  • submission_count - Cached count of submissions (use withCount('submissions'))

Creating Forms

Using the Facade

Create forms directly with the Polyform facade:

app/Http/Controllers/FormController.php

Using the FormBuilder

The FormBuilder gives you a chainable API with 26+ field methods:

app/Http/Controllers/FormController.php

Extensibility

Forms reference all related models via config('polyform.models.xxx'), so you can extend or swap out any model class. See the configuration docs for details.