Closed (fixed)
Project:
Webform
Version:
6.x-3.9
Component:
Miscellaneous
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
25 Jul 2011 at 07:29 UTC
Updated:
17 Feb 2014 at 05:14 UTC
Jump to comment: Most recent
Comments
Comment #1
carl.brown commentedYou could use Rules, which integrates with Webform. When both are installed, there's a new reaction event available in Rules called 'After a Webform has been submitted'. Use this as the trigger trigger and perform a Data Comparison against the options from your select box. Then, depending on the user's selection, use a redirect action to take the user to whatever page you want - you could also display a custom message for each option too.
Comment #2
govinda_roul commentedThanx for responding.Can you please provide the steps to do it ?
Comment #3
carl.brown commentedI've only done it on D7 with Webform 7.x and Rules 7.x-2, but I assume it would be roughly the same as all modules exist for D6, although the exact process may differ:
Download, install and enable Webform, Rules and the magic ingredient, Webform Rules.
The last module in the list adds the ability to act on Webform submissions.
Create your webform and build the select list as normal, with the key|value pairs, like this:
mon|Monday
tues|Tuesday
wed|Wednesday
etc...
It's important to note the 'field key' value for the select box you're interested in, as we will need this later on. The help text gives it all away really "Enter a machine readable key for this form element. May contain only alphanumeric characters and underscores. This key will be used as the name attribute of the form element. This value has no effect on the way data is saved, but may be helpful if doing custom form processing."
The first part of the key|value pair is the bit you will do the data comparison against in Rules. Once you're happy with your form, head over to the Rules module.
Create a new rule and for the reaction event, select "After a Webform has been submitted".
Add a condition of type 'Content is of type' - not sure this is 100% necessary, but won't hurt as some additional validation and will ensure that the next condition has the right data.
Add an 'And' condition
Add a condition of type 'Execute PHP code'. In the text area enter something along these lines:
$datais the submitted Webform data. It's stored in a nice big Drupal style array, so it's just a case of finding the right field value. Then we check what the value of the field actually is, and return TRUE for the condition we want to test for.Then add an action of 'Send Mail' under the 'System' heading. Add in the addresses to be emailed when a user selects this option and configure the email.
Finally, repeat this process for each of the other options in the select field, changing the recipient addresses and/or message body for each case.
If you're having problems finding the part of the submitted form data you're after, I tend to start off with a basic rule, which is just trigger on Webform submission and has one action; 'Display a message on the site'. Then in the message text area, i enter something like:
That will render all of the submitted form data in a nice way in the message box at the top of your page (depending on what theme you're using) and you'll be able to figure out the part you're looking for.
It could be made more tidy by using Rule Sets, so you only have one Action rule "webform submission", which triggers a Rule Set and there are separate rules for each select option within the Rule Set, but the explanation above should get the job done at least.
Hope that helps!
Comment #4
quicksketchUgh, this is why I hate rules. All this work to remove PHP execution from Webform and now it's starting all over again. Nothing like storing PHP code in the database. :P
Oh well, if it works for you that's great. Please don't submit any support requests to the Webform queue when you start getting WSODs or errors in "line 0 of exec()".
Comment #5
carl.brown commentedI worked this out while trying to solve the problem of email addresses being used as keys on a select option. Nothing like putting email addresses in the source code, eh?! ;p
As it happens, the powers that be decided that there had to be a crazy business-rule-goverened workflow and so I was unable to use Webform for my situation after discovering this. But if it gets someone out of a fix...
Thanks for the module though @quickstretch. It really is pretty killer and is on my list of 'install straight away' modules :)
Comment #6
govinda_roul commentedThax for the nice steps.
How can I link to display a block or contents in the same page after the form submission ?
Comment #7
pipicom commentedHello carl.brown,
Have followed your instructions and I have it almost done. My select code is like this:
Considering the above code how should I rewrite your code? Specifically i have a problem in the "name_of_select_field_key" part of the code. Not sure how I should fit name="submitted[hotel]" into this..
Have tried all combinations but in vain...
Thanks again for your time..
Comment #8
x.algorithm commentedI am trying to get this to work as well.
I am using:
Rules Rules (rules) Module Enabled 7.x-2.2
Rules Rules Scheduler (rules_scheduler) Module Enabled 7.x-2.2
Rules Rules UI (rules_admin) Module Enabled 7.x-2.2
Webform Webform (webform) Module Enabled 7.x-3.18
Webform Webform Rules (webform_rules) Module Enabled 7.x-1.5
My rule is:
After webform has been submitted -> Execute custom PHP code
-> Page redirect.
My safe key|values are:
1|Some Title
2|Some Other Title
3|A third title
4|A fourth title
5|A fifth title
6|A sixth title
Also, the rules evaluation log if this will help - I've been over it a bunch.
0 ms Reacting on event After a webform has been submitted.
12.223 ms Evaluating conditions of rule Brochure Blackjack 224. [edit]
13.614 ms The condition php_eval evaluated to FALSE [edit]
13.626 ms AND evaluated to FALSE.
13.674 ms Evaluating conditions of rule Data explosion. [edit]
13.685 ms AND evaluated to TRUE.
0 ms Rule Data explosion fires.
0.132 ms Evaluating the action php_eval. [edit]
0.519 ms Rule Data explosion has fired.
14.249 ms Finished reacting on event After a webform has been submitted.
And data explosion, which is just a print_r of the $data array is:
Thanks for any assistance you can give me.
I've referenced several posts already:
http://drupal.org/node/1505298
http://drupal.org/node/1700638
http://drupal.stackexchange.com/questions/32730/webform-redirect
The current one seems to be the most relevant.
Comment #9
quicksketchSorry for my unhelpful post in #4. PHP code in the database (and Rules) get me wound up some times.
In any case, if you're using Webform Rules, please post to the Webform Rules queue. I'm glad everyone seems to have found a solution here.