Contents

Cms\Behaviors\FormComponent

Overview

FormComponent behavior adds form handling capabilities to CMS components.

This behavior provides model binding, field schema exposure, validation, and AJAX save handlers. It follows the "schema in, template freedom out" pattern — the component defines what fields exist and their validation, while the theme developer has full control over HTML rendering.

Usage in a component:

public $implement = [
    \Cms\Behaviors\FormComponent::class,
];

public function formCreateModel() { return new MyModel; }
public function formGetFieldConfig() { return [...]; }
Extends

Public Properties

There are no public properties in the class.

Show inherited public properties

Inherited Public Properties

Protected Properties

protected array $htmlTypeMap

htmlTypeMap maps blueprint field types to HTML input types

protected array $skippedTypes

skippedTypes are field types not renderable in auto-generated forms

Show inherited protected properties

Inherited Protected Properties


Public Methods

public beforeDisplay()

public beforeDisplay(): void

beforeDisplay seeds the default form page variables so templates can reference them before submission

public formCoerceRelationValues()

public formCoerceRelationValues($model, $data, $allowedFields): array 

formCoerceRelationValues lets the component apply relation-backed values under its own trust rules

public formGetFieldNames()

public formGetFieldNames(): array 

formGetFieldNames returns the allowed field names from the config

public formGetFields()

public formGetFields(): array 

formGetFields returns field metadata for use in Twig templates.

Each field is returned as an array with keys: name, label, type, htmlType, options, required, placeholder, comment.

public formGetFileFieldNames()

public formGetFileFieldNames(): array 

formGetFileFieldNames returns field names that accept uploaded files

public formGetRejectedTypes()

public formGetRejectedTypes(): array 

formGetRejectedTypes returns field types that never accept postback values

public formGetThrottleRate()

public formGetThrottleRate(): int 

formGetThrottleRate returns the maximum submissions per minute per IP, zero to disable

public formHasFileFields()

public formHasFileFields(): bool 

formHasFileFields returns true if the form contains file upload fields

public formValidateFile()

public formValidateFile($name, $file, $fieldConfig): void 

formValidateFile validates a single uploaded file against size and extension rules

public onFormSubmit()

public onFormSubmit(): void

onFormSubmit is the default AJAX handler for form submissions.

It creates a model, fills it with filtered POST data, validates and saves, then fires an event for extensibility.

Show inherited public methods

Inherited Public Methods

Protected Methods

protected formCheckThrottle()

protected formCheckThrottle(): void 

formCheckThrottle enforces the submission rate limit for the visitor

protected formGetAllowedFileTypes()

protected formGetAllowedFileTypes($fieldConfig): string|null 

formGetAllowedFileTypes returns the allowed extensions for a file field

protected formGetValidatedFiles()

protected formGetValidatedFiles($fileFields): array 

formGetValidatedFiles returns uploaded files for file fields after validation

Show inherited protected methods

Inherited Protected Methods