Remembering the address of the calling page of a form (Drupal 7) I have created a little module that implements hook_menu and when the menu item is selected it displays a form that is defined as so:

function documentation_menu_nameform() {

  $form['documentation'] = array(
    '#type' =&gt; 'text_format',
    '#title' =&gt; t('Documentation'),
    '#default_value' =&gt; 'This project has not been documented.',
    '#format' =&gt; NULL,
    '#weight' =&gt; 0,
  );
  $form['submit'] = array(
    '#type' =&gt; 'submit',
    '#value' =&gt; t('Submit')
  );
  return $form;
}


Now when this menu item is selected it brings up a form at the address ?q=documentation_menu and in my form submission hook I would like to return to the page the user was on before they selected the menu item but I can't figure out how to access and/or store this path.
I would do this like so:

Have your menu item URL generated with destination parameter, for example:

/?q=documentation_menu&amp;destination=some/path/where/user/had/just/been

add a hidden field to your form and populate it with destination path

$form['destination'] = array(
  '#type' =&gt; 'hidden',
  '#value' =&gt; drupal_get_destination()
);


if you for some reasons can't add destination parameter to that URL, then you'll need to extract that URL from $_SERVER['HTTP_REFERRER'] and populate hidden field with it.

Then in your submit function just do a redirect to the path specified in that hidden field:

function documentation_menu_nameform_submit() {
  ...

  drupal_goto($_POST['destination']);
}