Is there a way to return the user to the referring page on submit? Maybe via php in the confirmation/redirect field?

Thanks!

Comments

quicksketch’s picture

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:

<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.

kthull’s picture

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.

quicksketch’s picture

Project: Webform » Webform Block
Version: 6.x-2.1 » 6.x-1.x-dev

Moving over to Webform Block module.

kthull’s picture

So does this mean it is not possible with a webform as a node? I don't need a webform block.

quicksketch’s picture

You can do it with a webform as a node per #1.

kthull’s picture

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.

budda’s picture

Project: Webform Block » Webform
Version: 6.x-1.x-dev »

Don't think this is related to the functionality of webform block module so moving back to the main webform project.

quicksketch’s picture

Status: Active » Closed (won't fix)

Sounds like this isn't going to happen then.

ealtman’s picture

Version: » 6.x-2.9
Component: User interface » Miscellaneous

Thank you kthull -- I was not redirecting, but merely hoping to capture the referer page data for a usability survey. That was a good solution!