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 element of a form. The desired url for redirection in this case was /user/myuser#profile-tab-7.

Asking in 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 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 . 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[''] = array('user/' .$user->uid, NULL, 'tabs-profile-7 ');



This is good to know. I am

This is good to know. I am wondering if the Profesionall Drupal Developer book mentions this? I will have to check later... But thanks for explaining the Drupal process goes through.

Pro Drupal Development

As a matter of fact I just looked and Pro Drupal Development does mention this.... If only I'd remembered to look while I was hunting down the solution. PDD proves its great value once again :)

There are times when you're

There are times when you're creating Web pages that you will need to create a link that goes to another place within the same document or to a specific location in another Web page. This is especially true for long web pages that require scrolling to locate specific places far down the page. For some long pages it helps to put an index of the page at the top of the page that links to information further down the page. When the user clicks on a link to move down the page there are usually links to get back up to the top of the page. This is accomplished through the use of named anchors.

In order to link to a specific location within a document, the destination page needs to contain a marker called a named anchor. If you know what the named anchor is called, you can create a link to it. A named anchor is designated by the filename.html#anchorname if it is in the same Web page as the link. See the code example below.

Named anchors are commonly used for long alphabetized or indexed lists, such as an index, a glossary, or a list of frequently asked questions. INstead of requiring users to scroll through the entire list of questions, you can create a list of the questions at the top of the page that link to the location in the page containing the answer to the specific question.

Submited by : Descargar Libros

Question 16: How does one create a named anchor?