I’ve built a “Quick Links” drop-down select box for my Drupal-based web app. The select box is implemented as a standard Drupal form, which appears on all pages in the site. When the user selects an option and submits the form, I want to redirect the user to the appropriate page, but have them return to the original page when they have finished.
e.g. user is on node/5, and selects a quick link which takes them to another form. When they have completed this form, I want them to be returned to node/5.
I have achieved this in other parts of the system using drupal_get_destination to append the ?destination=node/5 querystring parameter to the destination form, and this works nicely. However, in my quicklinks form submit handler, I’m setting form_state[‘redirect’] to set the target page, and if I add the ?destination= parameter it gets URL-encoded, and so isn’t picked up when my target form is submitted.
function dh_seo_quick_links_form_submit($form, &$form_state) {
$form_state['redirect'] = $form['#link_targets'][$link].'?'.drupal_get_destination();
}
Have I gone about this completely the wrong way? Is this redirection even possible? Could I do something clever with the $_REQUEST variables directly?
OK – I’ve worked it out. It seems that if you set a relative URL in the $form_state[‘redirect’] it gets URL-encoded, but an absolute URL will not:
redirects to myform%3Fdestination%3Dnode%252F5
redirects to myform?destination=node/5, which is what I wanted.