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
- $extendableStaticCalledClass - is the calling class when using a static method. (defined in October\Rain\Extension\ExtensionBase)
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
- $component - class. (defined in Cms\Classes\ComponentBehavior)
- $controller - to CMS controller. (defined in Cms\Classes\ComponentBehavior)
- $requiredProperties - that must exist in the component using this behavior. (defined in Cms\Classes\ComponentBehavior)
- $extensionHidden - are properties and methods that cannot be accessed. (defined in October\Rain\Extension\ExtensionBase)
- $configPath - specifies a path to the config directory. (defined in Cms\Classes\ComponentBehavior)
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.
Inherited Public Methods
- __construct() - the behavior. (defined in Cms\Classes\ComponentBehavior)
- extend() - this class with a closure. (defined in October\Rain\Extension\ExtensionBase)
- extensionApplyInitCallbacks() - (defined in October\Rain\Extension\ExtensionBase)
- extensionExtendCallback() - is a helper method for
::extend()static method. (defined in October\Rain\Extension\ExtensionBase) - extensionIsHiddenMethod() - (defined in October\Rain\Extension\ExtensionBase)
- extensionIsHiddenProperty() - (defined in October\Rain\Extension\ExtensionBase)
- getCalledExtensionClass() - (defined in October\Rain\Extension\ExtensionBase)
- getConfigPath() - locates a file based on it's definition. If the file starts with. (defined in Cms\Classes\ComponentBehavior)
- guessConfigPath() - guesses the package path for the called class. (defined in Cms\Classes\ComponentBehavior)
- guessConfigPathFrom() - guesses the package path from a specified class. (defined in Cms\Classes\ComponentBehavior)
- makeConfig() - reads the contents of the supplied file and applies it to this object. (defined in Cms\Classes\ComponentBehavior)
- makeConfigFromArray() - makes a config object from an array, making the first. (defined in Cms\Classes\ComponentBehavior)
- mergeConfig() - merges two configuration sources, either prepared or not, and returns. (defined in Cms\Classes\ComponentBehavior)
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
- extensionHideMethod() - (defined in October\Rain\Extension\ExtensionBase)
- extensionHideProperty() - (defined in October\Rain\Extension\ExtensionBase)
- getConfigValueFrom() - will apply the config getter convention. (defined in Cms\Classes\ComponentBehavior)