I have attached my webform inside a block. When the form is submitted I would like people to be redirected to the page they are on, as if they had never left.

at the moment i've tried this in the addition processing area:

[code]

$alias = drupal_get_path_alias($_GET['q']);
$node->webform['confirmation'] = 'internal:' . $alias;

[/code]

It's just taking me to the webform's url.

Any help would be much appreciated cheers.

Comments

quicksketch’s picture

If you don't enter a confirmation message at all, the user is redirected back to the webform URL. It sounds though that you're doing something unusual though, such as the Webform being displayed in a block?

jptaranto’s picture

Yes that's right the webform is displayed in a block (it appears as a javascript popup) - so I would like to skip redirecting to the url of the form and instead keep them on the same page.

Possible?

quicksketch’s picture

Hmm, well you can use the Additional Processing code to make the Webform redirect anywhere you want, but finding the originating URL could be a trick. See http://drupal.org/node/257100 for a description on how to set a custom URL redirection.

wansinn’s picture

I was sitting on the same issue now since hours and I found a strange but working solution:

the problem is that if i only redirect the form with "$node->webform['confirmation']="node/thisnodesid" (in the additional processing) i will be redirected "back" to the node where the webform is included as block (thats what i want) but as soon as the validation is not correct i will be redirected to the node of the webform (and thats bullshit because we want to stay in the node where the webform is included as block)

The solution is javascript:
Just change the action of the form with Javascript! This will redirect you to the node you want but the webform-functionality is still working.

Example:

First in the (maybe custom) "node.tpl.php" Insert a line that fills a session variable:

	$_SESSION['nid'] = $node->nid; 

Then set the confirmation redirect in the "additional processing" of the webform edit:

  $node->webform['confirmation']="internal:node/".$_SESSION['nid'];

At last in the (maybe custom) "block.tpl.php" insert following javascript AFTER printing the block content (print $block->content):

...

document.forms[0].action = "/node/ print $_SESSION['nid'];";

...

This will change the forms action and everything is fine ;)

I hope this will help anyone being confrontated with the problem as me ;)

Why all this webform in a block?
Because I was designing a ContentType with CCK and I wanted to implement a static form (which should have been a webform because of the submission workflow) in the node of the contenttype. So I decided to take the Field "blockreference" to include the block, so the author just has to select the form he wants to include...

quicksketch’s picture

Category: task » support
Status: Active » Closed (fixed)

Another interesting solution I've run across is having a hidden field on the first page of your form that contains %get[q] as the default value. Then you can set your redirect to return $form_values['submitted_tree']['hidden_field_name'] . Either way, I think we're good to close this issue.

volocuga’s picture

wansinn:

Thank you, good working solution

The java you wrote has a small typo. It shoul be:


<script type="text/javascript">

document.forms[0].action = '/node/<?php print $_SESSION['nid']; ?>';

</script>


volocuga’s picture

Ups, not so good. Confirmation message not showing

Aibu’s picture

Use the Ajax module for webform with the disable redirect plugin!