Skip to content

Migrate a core form ​

Migrate one form at a time. Load FormCompose under the Compose alias alongside core Form as shown in Your first form. Keep your controller's authorization, patchEntity(), validation, and saving.

php
<?= $this->Form->create($article) ?>
<?= $this->Form->control('title', ['class' => 'title-input']) ?>
<?= $this->Form->control('author_id', ['options' => $authors, 'empty' => 'No author']) ?>
<?= $this->Form->submit('Save') ?>
<?= $this->Form->end() ?>
php
<?php
$form = $this->Compose->bind($article);
?>
<?= $form->open() ?>
<?= $form->control('title')->attributes(['class' => 'title-input']) ?>
<?= $form->control('author_id')
    ->choices($authors)
    ->placeholder('No author') ?>
<?= $form->submit('Save') ?>
<?= $form->close() ?>
Existing concernFormCompose equivalent
create($entity) / end()bind($entity), then session open() / close()
Inline HTML attributes on control()attributes([...]) for the input, partAttributes(part, [...]) for other parts
String templates and widgetsApplication-owned PHP elements through a Theme; custom submission semantics through FieldTypeInterface
empty select optionplaceholder() accepts a label, true, false, or null. Optional single selects automatically get a blank choice.
Validation feedbackThe existing CakePHP context supplies errors and constraints; help and errors parts associate with the input
Reusable form configurationOptional blueprints; templates still own layout
CSRF, method overrides, tamper protectionKeep CakePHP middleware and FormProtectionComponent enabled; input rendering registers submitted names
postButton() / postLink()Helper shortcuts create independent protected forms; use block inside another form. See POST actions.

FormCompose does not forward arbitrary top-level field options as HTML attributes or implement every core helper convenience method. Check the field option reference when porting options. For grids, icons, or error wrappers, start with a PHP theme, rather than porting core widget subclasses or string-template substitutions.

Preserve configured names and IDs in custom markup. Render $field->input() to retain submission registration, or follow the explicit handwritten input contract. Hiding a field in a blueprint or layout controls presentation; authorize and validate submitted data in the application as usual.

For custom layouts, render enabled help and error parts alongside the input. Follow field parts for ordinary rendering, or the bound-field reference for handwritten markup.

Released under the MIT License.