How to redirect user to previous page after form submit? I can redirect user after adding a node to any another page but would like to redirect them to previous page they were linked from. Now I use the following code:

function user_add_node_form_foto_node_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  $form['actions']['submit']['#submit'][] = 'user_add_node_foto_node_form_submit'; 
}

function user_add_node_foto_node_form_submit($form, &amp;$form_state) {
  $form_state['redirect'] = 'node/add/foto';
}


How can I change a code to redirect users to previous page after submitting the form?

EDIT: Every foto node type has a node reference field "field_relate_to_gallery". By using this I created a gallery in Views and added a link "Add foto in gallery" on gallery page linking to add node form. I would like returning users back to gallery after adding a node "foto". That means that a have a lot of galleries with different ID and a cannot redirect the this form only to one particular gallery.

My Solution If someone is interested in. I did it by using node reference from url module. Now my user can add an image from gallery page (there is a link to add node form) and after submitting it he returnes to the gallery page.
You want drupal_get_destination(). This function creates a 'destination' query parameter suitable for use in l() that will redirect the user back to the page they came from after submitting the form. So, when you create your link to add a new node, use the l() function along with drupal_get_destination(). For example...

l('Add new foto', 'path/to/add/a/foto', array('query' =&gt; drupal_get_destination()))


That should do it.