Currently, there is a bit of code in form_example that sets the value of redirect to a string.

  // If we wanted to redirect on submission, set $form_state['redirect']
  // $form_state['redirect'] = 'node'; // Redirects the user to /node.

The problem is that when redirect is a string, the form is redirected but the status messages are lost. If the value of redirect is an array, it works.

I will post a patch that fixes this. I'm not sure why it is commented out, but I will leave it commented in the patch.

Comments

Anonymous’s picture

Status: Active » Needs review
StatusFileSize
new702 bytes

Patch as promised in the issue above.

Anonymous’s picture

Status: Needs review » Closed (cannot reproduce)

Actually, it looks like the original issue I was having wasn't related to it being a string value vs an array.

rfay’s picture

Yeah, actually, if you look at use of $form_state['redirect'] in core, it's almost always a string, but it can be used as an array to pass extra args to drupal_goto().

bfroehle’s picture

Category: bug » feature
Status: Closed (cannot reproduce) » Active

Actually, I'd suggest having an example where $form_state['redirect'] is an array.

This is feature confusing and poorly documented -- see #1095588: Form redirect w/ anchor causes problems - $form_state['redirect'] = "somepath/somepage#section2"; for example.

bfroehle’s picture

Status: Active » Needs review
StatusFileSize
new1.13 KB

See attached patch, which just adds another comment block describing advanced usage of $form_state['redirect'].

rfay’s picture

Status: Needs review » Active

I don't mind adding this into an example, but the key fix here is to improve the documentation. I think http://api.drupal.org/api/drupal/includes--form.inc/group/form_api/7 could be better. Even the (referred) http://api.drupal.org/api/drupal/includes--form.inc/function/drupal_redi... doesn't deal straight with this.

Would you mind chasing it in the documentation?

rfay’s picture

Status: Active » Needs work

x-post...

1. query is an array of name-value pairs: 'query' => array('foo' => 1)

2. Your patch needs to say in the comment what URL it would be redirecting to. In your example "The following would redirect to node?foo=1#bar" or something like that.

It can also mention that there are many other things supported by drupal_goto().

Thanks!

bfroehle’s picture

q0rban’s picture

Version: » 7.x-1.x-dev
Status: Needs work » Needs review
StatusFileSize
new1.87 KB

Here's an updated patch that addresses Randy's items in #7.

mile23’s picture

Title: $form_state['redirect'] value should be an array » Better docs on redirect in form_example_tutorial_8_page_two_submit()
Status: Needs review » Fixed

Very much way better commenting. :-)

Committed: http://drupalcode.org/project/examples.git/commitdiff/ed5bc430e36313cde5...

Thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.