Come together with the global Drupal community in Rotterdam, 28 Sept – 1 Oct 2026. Sessions, contribution, connection, and Early Bird savings until 8 June.
Yes you can do this via the additional processing, or you can do this by using PHP code in your redirect code. However I generally discourage the use of those fields, since debugging in textarea is rather difficult. Instead I'd suggest that you theme your webform-form.tpl.php file (see THEMING.txt) and just add this line of HTML somewhere inside the form:
Drupal treats any value in $_POST['destination'] specially and will override the normal redirection process. Unfortunately you can't just add a hidden field within webform with the key "destination" because Webform put all the fields into a parent group, so the element would actually be named submitted[destination]. Regardless, I think this is probably the most appropriate approach. If you're using Webform Block module, I'd suggest that this be implemented as a feature of that module, since that's the most likely situation for wanting this sort of behavior.
Adding that code returns a destination value of the webform node itself, not the page that launched the form in the first place. But thanks for the input...definitely giving me more fuel for the fire, though this seems like it would be handy a configuration option.
Thanks to the handbook page I came across today (http://drupal.org/node/257100), I finally got this working via the additional processing field.
As noted above in #2, the $_GET['q'] was taking me back to the webform and not the originating page (no doubt a flub on my part). And since I'm using pathauto, I needed to build the path first. I added a hidden form field called referring_node has a default value of %get[nid]. The link bringing the user to the webform is appended with the query string ?nid=[nid] via php in the node.tpl.php.
$path = 'node/'.$form_values['submitted_tree']['referring_node']; // drupal's standard node path
$alias = drupal_lookup_path('alias',$path,$path_language); // handy api to look up alias path
$form_values['submitted_tree']['return_path'] = $alias; // here we add a new value to the array
$node->webform['confirmation'] = 'http://www.domain.com/'.$form_values['submitted_tree']['return_path'];
As noted in the discussion thread on the handbook page, for some reason the only way to get the redirect to work was to use an absolute path. Using 'inner:'.$form_values['submitted_tree']['return_path'] did not work.
I'm sure this is not the most sound solution, but it solved my problem. Hope this helps.
Comments
Comment #1
quicksketchYes you can do this via the additional processing, or you can do this by using PHP code in your redirect code. However I generally discourage the use of those fields, since debugging in textarea is rather difficult. Instead I'd suggest that you theme your webform-form.tpl.php file (see THEMING.txt) and just add this line of HTML somewhere inside the form:
<input type="hidden" name="destination" value="<?php print $_GET['q'] ?>" />Drupal treats any value in $_POST['destination'] specially and will override the normal redirection process. Unfortunately you can't just add a hidden field within webform with the key "destination" because Webform put all the fields into a parent group, so the element would actually be named
submitted[destination]. Regardless, I think this is probably the most appropriate approach. If you're using Webform Block module, I'd suggest that this be implemented as a feature of that module, since that's the most likely situation for wanting this sort of behavior.Comment #2
kthullAdding that code returns a destination value of the webform node itself, not the page that launched the form in the first place. But thanks for the input...definitely giving me more fuel for the fire, though this seems like it would be handy a configuration option.
Comment #3
quicksketchMoving over to Webform Block module.
Comment #4
kthullSo does this mean it is not possible with a webform as a node? I don't need a webform block.
Comment #5
quicksketchYou can do it with a webform as a node per #1.
Comment #6
kthullThanks to the handbook page I came across today (http://drupal.org/node/257100), I finally got this working via the additional processing field.
As noted above in #2, the $_GET['q'] was taking me back to the webform and not the originating page (no doubt a flub on my part). And since I'm using pathauto, I needed to build the path first. I added a hidden form field called referring_node has a default value of %get[nid]. The link bringing the user to the webform is appended with the query string ?nid=[nid] via php in the node.tpl.php.
As noted in the discussion thread on the handbook page, for some reason the only way to get the redirect to work was to use an absolute path. Using 'inner:'.$form_values['submitted_tree']['return_path'] did not work.
I'm sure this is not the most sound solution, but it solved my problem. Hope this helps.
Comment #7
buddaDon't think this is related to the functionality of webform block module so moving back to the main webform project.
Comment #8
quicksketchSounds like this isn't going to happen then.
Comment #9
ealtman commentedThank you kthull -- I was not redirecting, but merely hoping to capture the referer page data for a usability survey. That was a good solution!