Reusable forms
Start with ordinary controls. Extract the part that repeats:
| What repeats? | Use |
|---|---|
| One field's settings | A FieldConfig. |
| Markup and classes | A PHP element or theme. |
| A set of fields | A form blueprint. |
Keep local configuration inline
Inside an open form:
echo $form->control('email')
->type('email')
->required();If several fields need those same settings, define a preset instead:
use FormCompose\Configuration\FieldConfig;
$email = FieldConfig::builder()
->type('email')
->required();
echo $form->control('email', config: $email);
echo $form->control('billing.email', config: $email)->label('Billing email');Configs are immutable: deriving a new config leaves the preset unchanged. See field configuration for named arguments and combining presets.
Extract a reusable form
A blueprint declares a collection once, then renders it wherever needed:
echo $this->Form
->form($article)
->blueprint('article')
->submit('Save article');The blueprint guide defines article and shows both automatic rendering and a manual view. Validation and saving continue through your existing CakePHP application.
Use blueprint defaults with a manual layout
Select the blueprint before bind(), then use the session's open(), control(), and close() calls. Follow the manual-view example.
For several independent sections, combine blueprints. For related records, use nested blueprints or repeated rows.