🎉 Kirby 5 is here! Learn more
Skip to content

Refactored Forms

We’ve refactored our Form and Field classes to provide a more stable and usable Form API for our models. You can now use the same Form API for your own projects to create forms in your templates.

See the Kirby\Form\Form documentation for more information.

use Kirby\Form\Form;

$form = new Form(
    fields: [
        'name' => [
            'label' => 'Name',
            'type'  => 'text'
        ],
        'email' => [
            'label' => 'Email',
            'type'  => 'email'
        ],
        'message' => [
            'label' => 'Message',
            'type'  => 'textarea'
        ]
    ]
);

$form->fill([
    'name'  => 'Peter Griffin',
    'email' => 'mail@example.com'
]);

$form->toFormValue();