I have a form submit, and in the final lines, I just want it to load a certain page with some args. My question is, does it matter if I use form_state['redirect'] vs drupal_goto? Both can take the args parameter, but it seems I'd want to use one over another based on the situation.

Whats the deciding factor here to use one versus the other?

thanks,
geremy

Comments

pobster’s picture

*bump*

Did you ever get an absolute answer?

Pobster

dutchslab’s picture

I never received an answer, absolute, or relative. ;)
geremy

newbuntu’s picture

I have the same question. I assume the link below says not to use drupal_goto. If they appear to behave the same, I guess I'll stick with redirect.
http://drupal.org/node/287683

I do have an observation: $form['#redirect'] is used in xyz_form() function. If you need to redirect conditionally in xyz_form_submit($form, &$form_state), then use $form_state['redirect']. Notice there is no # in front of "redirect". And make sure your 2nd parameter has an & in front of it (call by reference).

dutchslab’s picture

Here's an example of using form_state['redirect'] -- lets say on node submit, you with to make the subsequent page be the homepage instead of the node view page. Using hook_form_alter, you could set form_state['redirect'] to the homepage url.

if you aren't using form_state['redirect'] in your form submit, im not sure if others would be able to override it like described above.

geremy

Scott Reynolds’s picture

always us form_state['redirect']. If you use drupal_goto() you will short cut the form processing skipping any other form_submission functions that have attached themselves to the form. Thus, if you use path_auto and do a drupal_goto while processing a node form, a nice path will not be added to your node because the drupal_goto() was executed before pathauto's node submission handler was called.

ALWAYS use $form_state['redirect'], so that you play nice with other modules