There is one scenario where I want to go to particular div on page using drupal_goto().

Below is my code:

$path = '#textarea_comment'.$alert_id;

$options = array('bid' => $bookingid.$path );

drupal_goto("/fsaclientservice/viewreservation", $options);

In the above code the # is get replaced with %23 in URL and due to this I am not able to redirect to particular div on a page.

I have tried :


But still the URL is coming as %23 etc. Please help.


1 Answer 1


You just use the second argument the function takes.

drupal_goto("fsaclientservice/viewreservation", array('fragment' => 'add-reservation-note-form'));

Notice that in the code I wrote here, 'fragment' is a literal string you need to use as it is, and 'add-reservation-note-form' doesn't have any leading #. The documentation for that parameter is in url() because drupal_goto() calls that function to build the URL.

$options: (optional) An associative array of additional options, with the following elements:

  • 'query': An array of query key/value-pairs (without any URL-encoding) to append to the URL.
  • 'fragment': A fragment identifier (named anchor) to append to the URL. Do not include the leading '#' character.
  • 'absolute': Defaults to FALSE. Whether to force the output to be an absolute link (beginning with http:). Useful for links that will be displayed outside the site, such as in an RSS feed.
  • 'alias': Defaults to FALSE. Whether the given path is a URL alias already.
  • 'external': Whether the given path is an external URL.
  • 'language': An optional language object. If the path being linked to is internal to the site, $options['language'] is used to look up the alias for the URL. If $options['language'] is omitted, the global $language_url will be used.
  • 'https': Whether this URL should point to a secure location. If not defined, the current scheme is used, so the user stays on HTTP or HTTPS respectively. TRUE enforces HTTPS and FALSE enforces HTTP, but HTTPS can only be enforced when the variable 'https' is set to TRUE.
  • 'base_url': Only used internally, to modify the base URL when a language dependent URL requires so.
  • 'prefix': Only used internally, to modify the path when a language dependent URL requires so.
  • 'script': The script filename in Drupal's root directory to use when clean URLs are disabled, such as 'index.php'. Defaults to an empty string, as most modern web servers automatically find 'index.php'. If clean URLs are disabled, the value of $path is appended as query parameter 'q' to $options['script'] in the returned URL. When deploying Drupal on a web server that cannot be configured to automatically find index.php, then hook_url_outbound_alter() can be implemented to force this value to 'index.php'.
  • 'entity_type': The entity type of the object that called url(). Only set if url() is invoked by entity_uri().
  • 'entity': The entity object (such as a node) for which the URL is being generated. Only set if url() is invoked by entity_uri().
  • Is leading slash in the path really needed?
    – ya.teck
    Commented Apr 24, 2015 at 7:33
  • No, it isn't. Drupal core doesn't put it at the beginning of the path; for example, in drupal_goto('user/' . $user->uid);.
    – apaderno
    Commented Apr 24, 2015 at 7:50
  • But / is not the issue
    – Akki
    Commented Apr 24, 2015 at 8:40
  • 2
    This answers your question @Akki, any particular reason you've chosen to ignore it? Your recent edit makes it clear you've decided not to use this (correct) method. Why?
    – Clive
    Commented Apr 24, 2015 at 9:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.