$form_state['redirect'] is clobbered if set in a form builder function.

if this is by design, then we can convert this to a docs bug, because all core devs i asked in IRC (including davereid and catch) thought it should work if set in a form builder function.

attached is a test-only patch to illustrate the problem.

the code that does the dirty work starts at line 334 in form.inc:

    if ($check_cache) {
      $uncacheable_keys = array_flip(array_diff(form_state_keys_no_cache(), array('always_process', 'temporary')));
      $form_state = array_diff_key($form_state, $uncacheable_keys);
      $form_state += $form_state_before_retrieval;
    }
  }
CommentFileSizeAuthor
#8 drupal-1251616-8.patch2.64 KBdawehner
#4 drupal8.form-redirect.4.patch2.6 KBsun
#1 form.redirect.patch2.67 KBAnonymous (not verified)

Comments

Anonymous’s picture

StatusFileSize
new2.67 KB

Status: Needs review » Needs work

The last submitted patch, form.redirect.patch, failed testing.

chx’s picture

i remember this one as well from long, long time ago. you sure this hasnt been reported before?

sun’s picture

Title: $form_state['redirect'] doesn't work in form builder functions » $form_state['redirect'] does not work in form constructors
Version: 7.x-dev » 8.x-dev
Status: Needs work » Needs review
Issue tags: +API clean-up
StatusFileSize
new2.6 KB

This has been questioned and requested a couple of times in the past already, so it's definitely time to make it happen. I wasn't able to find a dedicated/focused, existing issue for this though.

Attached patch extracts the required changes from #1789768: search_box_form_submit() improperly calls form_set_error(). It doesn't contain the test additions from #1 yet.

Please note that #736564: Add #redirect property for form #type 'submit' to eliminate various submit handlers essentially wants to complement this with a button-level definition of #redirect. That and this issue together will make sense, as they're both moving the redirection target into the constructor/declaration layer.

sun’s picture

Note that the test changes are required, since language_negotiation_configure_url_form() defines a redirect target in the form constructor already (instead of the form submission handler), and apparently, someone has authored the test coverage based on the actual behavior instead of the code's intended behavior.

I manually tested the language negotiation form user interface to verify that the original intention of the code is correct. Thus, this patch fixes an additional UX bug in the language negotiation admin interface, along with bogus test expectations.

sun’s picture

Issue tags: -API clean-up

#4: drupal8.form-redirect.4.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +API clean-up

The last submitted patch, drupal8.form-redirect.4.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new2.64 KB

Just a rerole.

The last submitted patch, drupal-1251616-8.patch, failed testing.

Anonymous’s picture

Issue summary: View changes

make summary not fail to illustrate what i'm saying

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Issue summary: View changes
Issue tags: +Bug Smash Initiative

Discussed at BugSmash group triage. larowlan pointed out that this is outdated due to having $form_state->setRedirect now.

Therefore, closing as outdated. If this is incorrect reopen the issue, by setting the status to 'Active', and add a comment explaining what still needs to be done.

Thanks!

quietone’s picture

Status: Needs work » Closed (outdated)

Setting the correct status.