Problem/Motivation

If a user sets the $form_state['redirect'] via custom submit handler, webform module will not use it. Instead, it will always check and implement the redirects in the settings. Here is the line in which it does this check in the webform_client_form_submit(), https://git.drupalcode.org/project/webform/blob/08ff0884ac3d4f98324ddadf....

Steps to replicate

* Create form
* create hook_form_alter() updating redirect value

function hook_form_alter(&$form, &$form_state, $form_id) {
  // Add a submit handler to handle logic if certain fields are filled out.
  array_unshift($form['#submit'], 'feedback_form_submit');
}

function feedback_form_submit($form, &$form_state) {
  $form_state['redirect'] = 'node/2';
}

* Submit form and confirm not redirected per hook_form_alter() changes.

From my testing, webform forms will always have a null for $form_state['redirect'].

Proposed resolution

Since webform doesn't use the redirects value, we can add a is_null check before the redirect build linked above. If $form_state['redirects'] is null, build out message and url and override the redirect value. If redirect is populated, do nothing.

Note: This change will not support redirect setting in the hook_form_alter(). I didn't know this previously but $form_state['redirect'] is reset in drupal_build_form() 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;
    }

Remaining tasks

testing

User interface changes

n/a

API changes

n/a

Data model changes

n/a

Release notes snippet

Support redirects via the $form_state['redirect'].

Comments

robpowell created an issue. See original summary.

robpowell’s picture

StatusFileSize
new5.19 KB
new4.7 KB

Attached is both 7.4 and a backport for 7.3

robpowell’s picture

Status: Active » Needs review
liam morland’s picture

Status: Needs review » Needs work

Thanks for the patch.

We need to continue to use array() instead of [] since PHP 5.3 compatibility is still required.

The patch introduces some whitespace errors.

Instead of wrapping an if statement around a large block, have a if the returns early, leaving the existing code as-is.

Webform 3 doesn't get fixes like this anymore.

robpowell’s picture

StatusFileSize
new708 bytes
new577 bytes

Thanks for the feedback @liam-morland. I went ahead and rerolled based off the new releases fro 7.x-3.x and 7.x-4.x. I understand 3.x will not get this type of fix but I want to provide it for others that need the backport.

robpowell’s picture

Status: Needs work » Needs review
liam morland’s picture

Thanks for the patch. Instead of using is_null(), please use isset().

liam morland’s picture

Status: Needs review » Closed (outdated)

Drupal 7 is no longer supported. If this applies to a supported version, please re-open.

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.