Using named anchors with #redirect in forms
Working on a site using the jstabs module this evening I came across a bit of a challenge passing named anchors to the #redirect element of a form. The desired url for redirection in this case was /user/myuser#profile-tab-7.
Asking in #drupal led to the following tidbit from chx. (This is one of the many reasons Drupal is wonderful since Google searching didn't produce results and my experiments and requests of friends didn't produce the answer.) Anyway the challenge is that #redirect causes the form to call drupal_form_redirect() which in turn calls drupal_goto(). The drupal_goto() function takes the path, query and fragment as it's first three arguments.
drupal_goto($path = '', $query = NULL, $fragment = NULL, $http_response_code = 302)How then to pass these from #redirect. Putting the values in a string doesn't cut it as the special characters end up getting encoded in the URL and it doesn't work. The answer chx pointed out is to use array() to pass the values. The resulting code ends up looking like this:
$form['#redirect'] = array('user/' .$user->uid, NULL, 'tabs-profile-7 ');
Recent comments
1 day 11 hours ago
1 day 11 hours ago
1 day 15 hours ago
1 day 19 hours ago
1 day 22 hours ago
4 days 2 hours ago
1 week 2 days ago
1 week 2 days ago
1 week 2 days ago
1 week 3 days ago