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'].
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | 3055480_5_7.4.patch | 577 bytes | robpowell |
| #5 | 3055480_5_7.3.patch | 708 bytes | robpowell |
| #2 | 3055480_1_7.3.patch | 4.7 KB | robpowell |
| #2 | 3055480_1_7.4.patch | 5.19 KB | robpowell |
Comments
Comment #2
robpowellAttached is both 7.4 and a backport for 7.3
Comment #3
robpowellComment #4
liam morlandThanks 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
ifstatement around a large block, have aifthe returns early, leaving the existing code as-is.Webform 3 doesn't get fixes like this anymore.
Comment #5
robpowellThanks 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.
Comment #6
robpowellComment #7
liam morlandThanks for the patch. Instead of using is_null(), please use isset().
Comment #8
liam morlandDrupal 7 is no longer supported. If this applies to a supported version, please re-open.