Closed (fixed)
Project:
Webform
Version:
6.x-3.4
Component:
User interface
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
25 Oct 2010 at 18:42 UTC
Updated:
25 Mar 2013 at 06:00 UTC
Hi there,
I want to change the redirect URL and message of my webform dynamically. This is my current webform-form-30.tpl.php
<?php
// If editing or viewing submissions, display the navigation at the top.
if (isset($form['submission_info']) || isset($form['navigation'])) {
print drupal_render($form['navigation']);
print drupal_render($form['submission_info']);
}
?>
<?php
// Print out the main part of the form.
// Feel free to break this up and move the pieces within the array.?>
<div id="formheader">
<div class="formelement-column"><?php print drupal_render($form['submitted']['avondconferentie']);?></div>
<div class="formelement-column"><?php print drupal_render($form['submitted']['datum']);?></div>
</div>
<div id="mainformcontent">
<div id="eerstekolom">
<div class="formelement-column"><?php print drupal_render($form['submitted']['naam']);?></div>
<div class="formelement-column"><?php print drupal_render($form['submitted']['voornaam']);?></div>
<div class="formelement-column"><?php print drupal_render($form['submitted']['e_mailadres']);?></div>
</div>
<div id="tweedekolom">
<div class="formelement-column"><?php print drupal_render($form['submitted']['bedrijf']);?></div>
<div class="formelement-column"><?php print drupal_render($form['submitted']['telefoon_gsm']);?></div>
<div class="formelement-column"><?php print drupal_render($form['submitted']['fax']);?></div>
<div class="formelement-column"><?php print drupal_render($form['submitted']['redirectnid']);?></div>
</div>
</div>
<?php
$form['confirmation'] = $GLOBALS['base_url'].'/content/'.$form['submitted']['redirectnid'];
print drupal_render($form);?>
<?php // Print out the navigation again at the bottom.?>
<?php if (isset($form['submission_info']) || isset($form['navigation'])) {
unset($form['navigation']['#printed']);
print drupal_render($form['navigation']);
}?>
All the current pages on Drupal seem to suggest something along the lines of
$form['confirmation'] = $GLOBALS['base_url'].'/content/'.$form['submitted']['redirectnid'];
to be the way to change the redirect URL. redirectnid is a field that takes a variable from the URL through $get[nid]; printing out the field works as expected, but the submit button takes me to the default confirmation page anyway.
So, my question: how does one change the redirect url and message in webform-form-formid.tpl.php?
Comments
Comment #1
quicksketchYou can't modify the submit URL or message from the webform-form-[nid].tpl.php file. If you want to change the confirmation message, you can override webform-confirmation-[nid].tpl.php. If you want to do a redirect, you have to use hook_form_alter() in a custom module.
Comment #2
loopy29 commentedWell, is there no way to have the form redirect after submit to a different URL than the standard confirmation page based on one of the form values.
Let me explain my situation:
I have a node type "event" that allows people to sign up for the event. The node type "event" therefore contains a link "register" which, when clicked, opens webform with form id 30. The url of this register link contains several variables, such as:
?event=Testconferentie+vergadering+2&datum=2010-08-01+18%3A00%3A00&nid=22
I use these variables in my webform nr 30 for setting default values to various fields. For instance, the webform field "eventtitle" has a default value of $get['event'] and the webform field "redirectnid" has a default value of $get['nid']
Now I want to use the value of "redirectnid" for the confirmation URL, so I can go back to the original "event" node, where at the top of that "event" node a message would show "Thank you for registering".
I have tried the Webform PHP module to no effect. Does this issue have anything to do with it?
http://drupal.org/node/864010
But as I said, I would rather not use the Webform PHP module...
Comment #3
loopy29 commentedI assume that my issue also has something to do with, but the final users (sept 2010) also seem to be struggeling. Could you please explain the best way currently to redirect a user to a value of the form, and presenting a custom message on the redirected page.
Comment #4
quicksketchThe only way to have a dynamic redirect URL and a dynamic message is to use hook_form_alter() in a custom module and add on your own #submit handler. Then you can set $form_state['redirect'] and use drupal_set_message() for your message like you would with any other form.
Comment #5
loopy29 commentedunfortunately I am not familiar with writing my own modules... too bad. Thanks for the info though...
Comment #6
beckyjohnson commentedOk. I am totally willing to build my own module to do this but there is one thing I can't figure out. If i want to control the redirect based on what node the form is on, so that I can show the same form on many pages, how do i do i detect what node the form is showing up on?
Comment #7
quicksketchThis code is regularly used to detect which node a user is currently viewing:
The arg() function pulls values from the *internal, Drupal path*. So if you're on node/10, this would node_load(10). This works consistently if if this node has been given a path alias like "about/contact-us", because the internal Drupal path never changes.
Comment #8
attiks commentedYou can do this as follows:
Comment #9
beckyjohnson commentedThanks Attikis! I am going to try this out. It was really nice of you to post this.
Comment #10
quicksketchComment #11
serguitus commentedUps. It didn't work with $form['#redirect'] for me :( but #4 did work ok. Thanks quicksketch after a year :)
Comment #12
rooby commentedFor my webform in a block, in addition to what is in #4 I had to set the $form['#action'] in my form alter.
[edit] Actually if you put your submit handler on the submit button instead of the form it works without having to set the $form['#action'].