How can we go to particular #div on a page using drupal_goto()? 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' =&gt; $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 :

encodeurl()
rawencodeurl()


But still the URL is coming as %23 etc. Please help.
You just use the second argument the function takes.

drupal_goto("fsaclientservice/viewreservation", array('fragment' =&gt; '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().