You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Yannick de Lange 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. This is useful if you have the same form twice on a page and want to be able to differentiate them.
You can do this as follows:
<?phpnamespaceApp\FormHandler;
useApp\FormType\EditUserType;
useHostnet\Component\FormHandler\HandlerConfigInterface;
useHostnet\Component\FormHandler\HandlerTypeInterface;
finalclass EditUserFormHandler implements HandlerTypeInterface
{
publicfunction__construct(/* ... */) {/* ... */}
publicfunctionconfigure(HandlerConfigInterface$config)
{
$config->setType(EditUserType::class);
// to allow the same form on the same page multiple times$config->setName('my_custom_form_name');
$config->onSuccess(function (Account$user) {
// ...
});
}
}
This will internally call the FormFactoryInterface::createNamed() method with the name instead of the regular FormFactoryInterface::create(). This way Symfony can better tell which form was submitted.