Remembering the address of the calling page of a form (Drupal 7)
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']);
}