Skip to content

Redirect to index when saving without a button - #7892

Open
phcorp wants to merge 1 commit into
EasyCorp:5.xfrom
phcorp:fix_redirect_after_save_without_button
Open

phcorp wants to merge 1 commit into
EasyCorp:5.xfrom
phcorp:fix_redirect_after_save_without_button

Conversation

@phcorp

@phcorp phcorp commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Problem

AbstractCrudController::getRedirectResponseAfterSave() picks the redirect from the submit button that was clicked (ea[newForm][btn]). A browser only sends that parameter when the form is submitted with one of its buttons. When a new/edit form is submitted another way, e.g. form.submit() in JavaScript or a browser extension, the parameter is missing and the match falls into its default branch. That branch redirects to the dashboard, which none of the form buttons does.

Also, the getRedirectResponseAfterSave() example in doc/crud.rst reads ['btn'] with no default, which triggers an "Undefined array key" warning in that case.

Fix

  • A missing button name is handled as the main button of the form, Action::SAVE_AND_RETURN, so the user goes back to the index page.
  • The docs example now uses ?? null.

Tests

NewTest::testRedirectAfterCreationDependsOnTheSubmitButton() and EditTest::testRedirectAfterUpdateDependsOnTheSubmitButton() (DefaultApp, Category) cover:

  • each button: return to index, add another, continue editing
  • no button at all, which redirected to /admin on 5.x and now redirects to the index URL

Results:

  • make tests ARGS="tests/Functional/Default/Crud/": OK (75 tests)
  • make tests-parallel: OK (3692 tests)
  • phpstan and php-cs-fixer: no errors

@phcorp
phcorp force-pushed the fix_redirect_after_save_without_button branch 2 times, most recently from 4cddd3e to 041340f Compare November 7, 2026 02:06
getRedirectResponseAfterSave() chooses the redirect from the name of the
submit button (ea[newForm][btn]). When a new or edit form is submitted
without any of its buttons, e.g. with form.submit() in JavaScript or by a
browser extension, that parameter is missing and the user was redirected
to the dashboard, which is not what any of the form buttons does.

A missing button name is now handled as the main button of the form
(Action::SAVE_AND_RETURN), so the user goes back to the index page.

The getRedirectResponseAfterSave() example of the docs now also handles a
missing button name, as reading it without a default triggers a warning.
@phcorp
phcorp force-pushed the fix_redirect_after_save_without_button branch from 041340f to 0e4c1c5 Compare November 8, 2026 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant