Redirect Drupal Webform Submissions Based on Answers

Redirect Drupal Webform Submissions

This week one of our members came up with an interesting question about the Webform module. They wanted to redirect users to different pages depending on their answers.

Here’s how you can make that work using Webform conditionals.

  • Install both Webform and the Token module.
  • Set up the Webform and the question that you want to rely on for the redirection. In this example, we’re using a “Select option” field:

You’ll need to make sure that two things are set up correctly here.

  • Make sure that you remember your “Field Key”:
  • Make sure that you have keys set up for each answer:
  • Go to the “Form settings” tab.
  • Scroll down to “Redirection location” box.
  • Click “Browse available tokens”.
  • You’ll see an overview of all the tokens you can use. In this example, we want to use a “Webform submission value”.

Here’s how the submission value is used. We enter “favorite” to choose the field, and we use “key” to say that want the direction to be based on the answer.

Now when people complete the webform, they will be directed to a new URL, based on their answer:

Instructor

  • Steve is the founder of OSTraining. Originally from the UK, he now lives in Sarasota in the USA. Steve's work straddles the line between teaching and web development.

0 0 votes
Blog Rating
Subscribe
Notify of
15 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Marcus Burnette

This is great! In a similar manner, I’ve rerouted submission emails based on answers as well.
If you make your keys email addresses, you can send submission emails to different people based on the answer to the question.
(Maybe I’ll do a write-up on my own blog about that sometime….)

steve

Hi Marcus
Yes, that’s a great use for this idea. This tutorial is over 3 years old now, but walks through how to do it [url=https://www.ostraining.com/blog/drupal/webform-different-emails/]https://www.ostraining.com/…[/url]

Sarah Baker

I was just about to ask if this could be repurposed for emails! Thank you for sharing.

robert.kent87

Could you use this to create a decision tree interface? For example the first page would have a question then depending on your answer you’d be taken to another page with a further question eventually leading to a content page?

steve

Hi Robert
Yes, it would involve a lot of different webforms, but that could work.

ARUN AK

I checked above mentioned configuration. It is not set for my webform but still it redirecting on submit. Is there any other way to do the same?

Ricardo

Hello Steve,

I am doing exactly what you explain; the key for my form field is also “favorite”, and the URL in the key for the test option in my Select Option field is “/content/test”, which is a test page, but when I submit the form instead of being redirected to the test page, I get a “Page Not Found” error and in the URL a weird “[submission%3Avalues%3Afavorite%3Akey]?sid=16126” after the website domain. By the way, this is what I am putting in Custom URL under Form Settings [submission:values:favorite:key]

Thanks so much in advance for your assistance!

daniel-pickering

Hi Ricardo
What does the error log in the dblogger say?
Thanks

Daniel

Ricardo Ruiz

Hello Daniel, thanks for replying. Where do I check that?

daniel-pickering

Under Reports / Recent log messages.
You should always check it for errors.

Ricardo Ruiz

TYPE page not found

DATE (just the date)

USER (just the user)

LOCATION http://webdomain/%5Bsubmission%3Avalues%3Afavorite%3Akey%5D?sid=16201

REFERRER (the page where the link is)

MESSAGE [submission:values:favorite:key]

SEVERITY warning

HOSTNAME (IP)

OPERATIONS (nothing)

daniel-pickering

I’d check all your settings for it seems it doesn’t know what to do with the submission.
Thanks

Daniel

Yane

thanx a lot! just what i need!

question: can I add  OR statements somehow?
If any one of these values is no then redirect to the “no” page.

[submission:values:commit:no]
[submission:values:visitation:no]
[submission:values:schedule:no]
[submission:values:deadline:no]
[submission:values:understand:no]

tried this:
[submission:values:commit:no] || [submission:values:visitation:no] || [submission:values:schedule:no] || [submission:values:deadline:no] || [submission:values:understand:no]
 received this:
The requested page “/%20%20%7C%7C%20No%20%7C%7C%20%20%20%7C%7C%20%20%7C%7C%20%20” could not be found.

Sarah

What if you need your submission to redirect to a different domain? Is that possible with tokens?

15
0
Would love your thoughts, please comment.x
()
x