Skip to content

How to Submit a Form with Multiple Buttons #11777

@LPodolski

Description

@LPodolski

Documentation is incorrect in:
https://github.com/symfony/symfony-docs/blob/master/form/multiple_buttons.rst
https://symfony.com/doc/current/form/multiple_buttons.html

in code:

$form->getClickedButton()

this method do not exists

if you use example above, that creates $form variable:

$form = $this->createFormBuilder($task)
    ->add('task', TextType::class)
    ->add('dueDate', DateType::class)
    ->add('save', SubmitType::class, ['label' => 'Create Task'])
    ->add('saveAndAdd', SubmitType::class, ['label' => 'Save and Add'])
    ->getForm();

return type of $form variable would be FormInterface

and form interface does not contain method getClickedButton

  1. If method above would return Form, which has getClieckedButton method, then
/**
     * Returns the button that was used to submit the form.
     *
     * @return ClickableInterface|null
     */
    public function getClickedButton()

returns ClickableInterface

which does not have method getName

used in example:

$form->getClickedButton()->getName()

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions