Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
forms system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
17 Mar 2011 at 18:36 UTC
Updated:
29 Jul 2014 at 19:27 UTC
Jump to comment: Most recent file
Comments
Comment #1
bfroehle commentedComment #2
rfayActually, I think an example is in order here. Essentially the whole thing makes sense with an example in the docs. The problem is when the docs say "oh like drupal_redirect()", which says "oh, like url()", etc.
Comment #3
bfroehle commentedWhat are some good examples?
Comment #4
rfayI just meant a demonstration example, so
"To redirect to xxx/yyy?zzz=32#something,
$form_state['redirect'] = ...
"
Comment #5
bfroehle commentedI've added two examples to the patch in #1. See attached.
Comment #6
rfayWorks for me. Thanks.
Comment #7
geerlingguy commentedThis is ridiculously helpful. I've been reading through all the redirect pages in the past hour (doesn't help that the D6 method of
$form['#redirect']was changed and not very well documented until recently...), and this issue has resolved a lot of questions I still had.Please commit asap, to avoid any more confusion here.
Comment #8
rfayD8 first...
Comment #9
webchickNice! This looks like a great improvement.
Committed to 8.x and 7.x.
Comment #11
dhruba.jyoti.saha commentedHi bfroehle and All,
I m working with D 7.12 and need to redirect the anonymous users to 'user/login' page with customized o/p. I tried to do it by using 'hook_form_form_id_alter(parameters)' for the 'user_login_block' form. By default this form has three more validations. So, to maintain the default drupal validations, I kept my validation callback at the end of the array :
$form['#validate'] = array('user_login_name_validate', 'user_login_authenticate_validate', 'user_login_final_validate', 'my_custom_validate');
And, in the definition of 'my_custom_validate' I tried to use all the possible ways suggested in drupal.org and IRC (#drupal, #drupal-support)to redirect based on the new approach of D 7 and even tried drupal_goto(). But it always redirected me to 'node' page.
Then I tried by keeping my custom call back at the beginning of the array so that it gets executed at the first. But no results.
Now finally I tried the below approach for 'my_custom_validate' (can keep at the first or last of the array. if at the first need to do custom validations and if at the end can use drupal default validation):
function my_custom_validate($form, &$form_state) {
global $base_path;
header('Location: ' . $base_path . 'user/login');
}
This works pretty good.
Note: $form_state['#redirect'] works very nice with a custom form.
Note : I am not much clear about why $form_state['#redirect'] or drupal_goto() didn't work where as PHP 'header' worked. can n e one pls help me understanding it? Thanks in advance.