Skip to content

Using Named Forms

Iltar van der Berg edited this page Apr 6, 2017 · 6 revisions

In some cases you might want to create a named form. The form handlers support this by also configuring a name.

<?php
namespace App\FormHandler;

// use ...

final class MyFormHandler implements HandlerTypeInterface
{
    public function configure(HandlerConfigInterface $config)
    {
        $config->setType(MyType::class);

        // to allow the same form on the same page multiple times
        $config->setName('my_custom_form_name');

        $config->onSuccess(function ($data) {
            // ...
        });
    }
}

This will internally call the FormFactoryInterface::createNamed() method with the name instead of the regular FormFactoryInterface::create().

Clone this wiki locally