By setting the $node->webform['confirmation'] key, you can change where Webform redirects the user after form processing has been completed. Use the code below to change the URL based on your own criteria.

// Redirect to Google when done.
$node->webform['confirmation'] = 'http://google.com';

// Redirect to node 1 (an internal Drupal path).
$node->webform['confirmation'] = 'internal:node/1';

// Redirect to the contents of a hidden field.
$node->webform['confirmation'] = $form_values['submitted_tree']['my_hidden_value'];

Comments

doublejosh’s picture

This was my goal, get to the user edit page post registration because of an upon-join webform survey...

global $user;
$node->webform['confirmation'] = 'internal:user/'.$user->uid.'/edit';

Be advised all that this code belongs in the Webform Advanced Settings > Additional Processing:

/:)

Jo Wouters’s picture

Very usefull: webforms will add &sid=xxx to the url, so you know the unique submissionID.

avangelist’s picture

I want to change the action - I don't want it to send a message to an email address. I want it to be processed by a custom php form.

How do you do that?

Web Developer
Music Photographer

smartmark’s picture

Actually the email is not sent by default, but the sumitted data are stored in DB as a separate content "webform".

You can set the action in Configuration -> Webform advanced settings -> Additional Processing.

javanehese’s picture

I try to follow this tutorial, but no redirection to my specific page.

tcniki’s picture

I have the same problem. Redirecting to google work perfectly, but when I build the redirect url and assign it to a variable, it doesn't work.

Dave Reid’s picture

Make sure if it's a local path you add 'internal:' before the path.

shoaib.nawaz’s picture

How can I pass more variables. I tried

$node->webform['confirmation'] = 'internal:node/{node_id}' . '?{var1}={value1}&{var2}={value2}&{var3}={value3}';

But the resultent URL becomes

node/{node_id}%3F{var1}%3D{value1}%2526{var2}%3D{value2}%2526{var3}%3D{value3}?sid={sid}

How can we manage that?

kchown’s picture

Hello
This was giving me the same problem.
Now I have found a work-around - by using a full url, as though it was an external link, it is no longer mashing the question mark etc....

$node->webform['confirmation'] = 'http://www.montrealandottawaconference.ca/site/node/2?parent='.($form_values['submitted_tree']['parent_family_name']);

hope that helps

Heidi Fiscus’s picture

and other things. Nothing is working for me.

I basically want to create a redirect from a webform (node/661) submission to a poll (node/660).

I tried:

1. internal:node/661 (using Full HTML format)
2.


// Redirect to node 1 (an internal Drupal path).
$node->webform['confirmation'] = 'internal:node/661';

(using PHP format)

Does anyone know how to create a working redirect in a webform? Step by step instructions please.

stinky’s picture

Just wondering if you ever got this working. I'm able to redirect my confirmation URL using the below code in the webform "Additional Processing Field." Note I'm still using Drupal 5.23, I know I need to upgrade, but can't at the moment.

This code WORKS!
<?php
$node->webform['confirmation'] = 'internal:node/1493';
?>

but, I need to send two variables from my webform to populate values on a form on node/1493.

I've tried many many variations, but can't seem to send the variables. I've tried the entire URL (instead of internal:node/) and have looked at a tone of documents (e.g., http://drupal.org/node/323553, http://drupal.org/node/257100, http://drupal.org/handbook/modules/webform/submission-code, etc.)

For example, this doesn't work:
<?php
$node->webform['confirmation'] = 'internal:node/1493?AMT='.($form_values['submitted']['amount']);
?>

....
The goal is to create a two step form. The data I need stays in my db via webform. The amount and name variables are passed to a node that contains a form that posts to the payment site (like paypal).

mwoodwar’s picture

I've been reading about webforms all morning, and think that it will do what I want...but am unclear about the details.

I have a form that has 5 different donation amounts (paypal) and each one has a specific paypal 'target' url/form. How can I say...if donation=$50-->thisurl if donation=$75.00--that url.

I've inherited this project and don't know much about the paypal piece, but I can see by looking at the code on the page that each amount$ has a separate paypal form associated with it.

Thanks

Mark

kchown’s picture

Hi
I bashed my head against the wall on this for two days, and then I updated to the latest version of webform.... now I can redirect.

I wrote the following to handle a conditional situation.....

  if ($form_values['submitted_tree']['children']['children_question'] == 'No - Non')
   {
    $node->webform['confirmation'] = 'internal:node/244';
  }
  if ($form_values['submitted_tree']['children']['children_question'] == 'Yes - Oui')
   {
    $node->webform['confirmation'] = 'http://www.velotour.synodemontrealetottawa.ca/';
  }

seems to be working..... something like that may help with your paypal question.

mwoodwar’s picture

Thanks Kent, I'll give it a try

awm6392’s picture

In your code, what are each of the parts supposed to be? I assume ['children_question'] is a specific component and ['children'] is the name of the form yes? If my form is named so that no name appears above the form when embedded as a block on pages, could I put [''] or would that not work? Also, how would this work for radio buttons? Same way?

I only ask because I tried this method in my webform and if I submit a test, no redirect actually occurs.

loophole080’s picture

i've managed to get redirect working, but can't figure out how to make it conditional upon the update action - in other words what i want to do is have a specific redirect when the webform is deleted

any ideas if this is possible using the method described here?

kthull’s picture

In my setup I'm using pathauto and I used the following solution to redirect to the node the user was on before clicking a link to fill out a webform request:

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

Hope this helps.

Kevin

Personal: @kevinjthull
Foodies: @sharednoms
Food Trucks: @foodtruck50

lacrosse_20’s picture

It's taken me a while, but I finally figured out why $node->webform['confirmation'] wasn't working for me. This is probably because I'm using webform-6.x-3.0-beta2, but for the redirect to work for me, I had to use $node->webform['redirect_url']. I hope this helps others...

This probably has something to do with the changes brought about by http://drupal.org/node/520524 , but TLDR....

mattcasey’s picture

So I was so close to implementing this until I updated to the new module and lost the Additional Processing field. I understand this is a security issue and the author suggested using a module. I have manually created a hidden "referring_node" component in my webform and am trying to change redirect_url with a custom module using hook_alter. So far, drupal doesn't even see my module but hopefully I'm in the ballpark. I created a .info file and .module in a webform_redirect folder inside sites/default/modules:

The webform_redirect.info file:

; $Id$
name = "Webform redirect"
description = "Redirects users to node submitted as nid-nid."
core = 6.x
package = Webform
dependencies[] = webform

The webform_redirect.module file:

<?php
// $Id$

function webform_redirect_form_alter(&$form, $form_state, $form_id) {
	switch ($form_id) {
// case for my form_id
	case 'webform_client_form_1':
	$output .= dsm($form);
/* 		$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['redirect_url'] = 'http://mysite.com/'.$form_values['submitted_tree']['return_path']; */
		break;
	}
}

Since I'm using a module, I would like to create something eventually that would create the referring_node component, as well as support for taxonomy pages, and other people could avoid the hassle!

scip’s picture

I don't know if this might help someone, but I have had problems passing query strings.
Internal links don't work as per heidihillyard.
So I set the confirmation url to an absolute http:// using something like url('node/120/', array('query' => 'query=' . $the_query, 'absolute' => TRUE)) but this fails at line 1903 of webform.module
elseif (valid_url(trim($node->webform['confirmation']), TRUE))

I know this is a hack, but what worked was removing this code.

Todd Young’s picture


It's taken me a while, but I finally figured out why $node->webform['confirmation'] wasn't working for me. This is probably because I'm using webform-6.x-3.0-beta2, but for the redirect to work for me, I had to use $node->webform['redirect_url']. I hope this helps others...

Thanks lacrosse_20 - that worked!

SWMdave’s picture

Just giving back- spent almost 25 minutes on this and figured i'd save someone else the headache since its not listed.

<?php
// Redirect to url and add parameters from hidden fields.
$node->webform['confirmation'] = $form_values['submitted_tree']['BASEURL?id=XX'] .'&PARAM2=' .$form_values['submitted_tree']['PARAM2'] .'&PARAM3=' .$form_values['submitted_tree']['PARAM3'] .'&PARAM4=' .$form_values['submitted_tree']['PARAM4'];
?>

this will redirect to: http://www.XXX.com?id=XX&PARAM2=XXXXX&PARAM3=XXXX&PARAM4=XXX

could have easily been:

<?php
// Redirect to url and add parameters from hidden fields.
$node->webform['confirmation'] = $form_values['submitted_tree']['BASEURL'] .'?ID=' .$form_values['submitted_tree']['PARAM2'] .'&PARAM3=' .$form_values['submitted_tree']['PARAM3'] .'&PARAM4=' .$form_values['submitted_tree']['PARAM4'];
?>
LaurenW’s picture

I am trying to work with the suggestions provided here to redirect to a different url based on 2 options in my form (course and location). I tried this solution and several others, but am receiving an error that form_values is undefined. I am not that familiar with PHP, so this may be a simple problem.

I have tried this code in my template.php:

function liquent1_form_alter(&$form, &$form_state, $form_id){
    switch($form_id){
        case "webform_client_form_201": // change XX to your webform node id
		$form['#node']->webform['redirect_url'] = 
		$form_values['submitted_tree']['BASEURL'] .'training/course-registration/register/' .'course=' .$form_values['submitted_tree']['course'] .'/location=' .$form_values['submitted_tree']['location'];
    }
}

This IS redirecting, but not where I would expect. It's going to [BASEURL]/training/course-registration/register/course%3D/location%3D?sid=276 and does not seem to be loading the course value and location value as I would expect. I am not sure where the "?sid=276" part is coming from.

Any help would be very appreciated! Thank you.

presich’s picture

Hello.
I use webform as contact form in the bootom of my node page. It's assosiated with the node, and admin get an email that sbdy interests about certain node.

But I want user who submits webform stay on the same page ang get a confirmation ("Thanks!!tra-la-la...").

To stay on the same page I must use redirection to that page BUT in such case I can't show confirmation text.

Please help))

leprechau’s picture

I couldn't for the life of me get the current webform 3.x to redirect by setting redirect_url via the 'additional processing' input with the webform_php module ... I could put print_r($node->webform, true) into a drupal_set_message() and see that it was being set...but webform was not redirecting, so I came up with a bit of a round about solution that works really well.

1) Instead of setting the following:

$node->webform['confirmation'] = 'Thank you for your submission!';
$node->webform['redirect_url'] = '<front>';

I set this:

$_SESSION['something_here']['confirmation'] = 'Thank you for your submission!';
$_SESSION['something_here']['redirect_url'] = '<front>';

2) I then set the redirect url for the whole webform to a custom page containing the following php body:

// get information from our session
if (!empty($_SESSION['something_here']['redirect_url'])) {
    // check for message
    if (!empty($_SESSION['something_here']['confirmation'])) {
        drupal_set_message($_SESSION['something_here']['confirmation']);
    }
    // redirect to path
    drupal_goto($_SESSION['something_here']['redirect_url']);
}
else {
    // redirect to frontpage
    drupal_goto('<front>');
}

This worked really well for me and I haven't had any problems since....of course this is just an example, in reality this would be much too complicated for a single static message and frontpage redirect.

danmed’s picture

I am quite new with Drupal.
Have been trying to get a dynamic URL to be used for redirect after form submit using a custom module.
As I am still getting nowhere, is there something new on the subject or is the solution above (load values in Session and re-use in a custom page) the only one working?
By the way, the solution above, though clever, means 2 redirects.
thanks

dadikof’s picture

Add submit handing function after webform's original webform_client_submit().

Example code for module solution:

function mymodule_form_alter(&$form, &$form_state, $form_id) {
	if (substr($form_id, 0, 20) == 'webform_client_form_') {

		// here goes the magic :) 
		array_push($form['#submit'], 'mymodule_submit_redirect');
	}
}

function mymodule_submit_redirect($form, &$form_state) {
		$form_state['redirect'] = "whatever-you-want"; // internal or external path 
}

Simple, easy, and took hell of a time to figure it out ;)

Pozdrawiam,
Radek Pycka

jennypanighetti’s picture

I need a conditional redirect and redirect_url doesn't work for me either. I can error_log the output, but the form doesn't go to that page. Very odd.

I'm using Drupal 6, webform-3.2.

goodwillhinton’s picture

I am trying to get this to work but am having trouble. Here is my code:

<?php
$component_cid = 3;

  if ($form_values['submitted'][$component_cid] == 1)
   {
    $node->webform['redirect_url'] = 'http://www.homestretch.org/WAYS_TO_HELP-Donate_Online.htm';
  }
  if ($form_values['submitted'][$component_cid] == 2)
   {
    $node->webform['redirect_url'] = '
internal:node/138';
  }

?>

When I submit the form, I get a blank page. Any thoughts on what I am doing wrong?

Thanks!

primerdp’s picture

There is a bug s.t. the code featured in this article doesn't work. See http://drupal.org/node/864010

jfinkel’s picture

Thanks, primerdp. The solution is to use drupal_goto() rather than change the value of $node (a change that will not be sent back to the webform module).

ainz’s picture

Check out my post about redirecting using webform 3.x. This worked for me http://drupal.org/node/865326#comment-3773072

Hope it helps!

rpataca’s picture

I'm trying to figure out how to send the user to a thank you page inside a lightbox.

// Redirect to Google when done.
$node->webform['confirmation'] = 'http://google.com';

Works great... but I need to some how add the rel="lightframe" into the mix.

Is this possible?

<a href="http://www.google.com/" rel="lightframe">Google</a>

This will open google in my lightbox but how can I open my webform's thank you page in the lightbox?

naseem_sarwar’s picture

hi,

i have tried this code but it is not working... here is my code...

$version6 = $_POST['submitted']['light_blue']['version'];
if($version6 ==t( '12'))
{
$node->webform['confirmation'] = 'http://www.google.com';

//$node->webform['confirmation'] = 'internal:node/30';
}
but still unable to redirect to any of the page. please advise. where i m doing wrong...thanks in advance

one more thing which redirection item should i select to work it properly.
confirmation page or no-redirect??

jpschroeder’s picture

For those of you interested in using this from hook_form_alter (perhaps you are modifying a webform dynamically like me) changing the redirect is as easy as this:

<?php
function example_form_alter(&$form, &$form_state, $form_id){
	switch($form_id){
		case "webform_client_form_XX": // change XX to your webform node id

			$form['#node']->webform['redirect_url'] = "http://www.google.com"; // change the url to whatever you want

		break;
	}
}
?>
rajesh.vishwakarma’s picture

Where can I write this code? Is there any hook or ....?

// Redirect to Google when done.
$node->webform['confirmation'] = 'http://google.com';

// Redirect to node 1 (an internal Drupal path).
$node->webform['confirmation'] = 'internal:node/1';

// Redirect to the contents of a hidden field.
$node->webform['confirmation'] = $form_values['submitted_tree']['my_hidden_value'];