Skip to content

Added alternative syntax using getClickedButton() #7931

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 3, 2017
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions form/multiple_buttons.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,12 @@ querying if the "Save and add" button was clicked::

return $this->redirectToRoute($nextAction);
}

Or you can get the button's name by using the
:method:`Symfony\\Component\\Form\\Form::getClickedButton` method of the form::

if ('saveAndAdd' === $form->getClickedButton()->getName()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to be careful here. Depending on how the form was submitted getClickedButton() may return null. Then, this example would run into an error as getName() could not be executed.

// ...
}