Right now, submission data is not exposed to rules except by way of token replacement or custom php actions.
This patch exposes submission data in a "first-class" way.

In this patch:

  • includes #1948824: Unable to pass submission data into action set component to fix implementation of hook_rules_data_info(). (This patch will require a re-roll when that gets in.)
  • extends hook_rules_data_info() to expose all properties of a submission
  • provides better access to submission component values
  • class WebformRulesSubmissionWrapper implements RulesIdentifiableDataWrapper to provide entity wrapped access to webform submissions
  • New condition "Submission to a particular webform", which works almost identically to "Webform has name", except it relates the submission data to the webform id, instead of text-to-text. (I chose to implement this new condition as separate, rather than combine them, in order not to break any existing rules.) This relation allows for:
  • Rules assertion to expose webform components only for the selected webform, instead of exposing all webform components for all selectors (which would not be scalable).

Areas for continued development:
* provides read-only data. setter callbacks not implemented.

CommentFileSizeAuthor
#69 exposed_submission_workaround.png46.54 KBsthomen
#61 webform_rules-expose_submission_data-2020149-61.patch1.54 KBselfuntitled
#56 webform_rules-expose_submission_data-2020149-56.patch724 byteslex0r
#55 webform_rules-expose_submission_data-2020149-55.patch603 byteslex0r
#53 user-entity-creation-through-webform_rules-email.png312.68 KB4aficiona2
#53 user-entity-creation-through-webform_rules-username.png268.72 KB4aficiona2
#53 user-entity-creation-through-webform_rules.png77.29 KB4aficiona2
#41 create_entity_rule_laz.png50.8 KBLaz5530
#41 create_entity_rule_laz_2.png32.56 KBLaz5530
#40 rulesimage.png27.25 KBkevster111
#34 webform_rules-expose_submission_data-2020149-30.patch3.44 KBLaz5530
#32 webform_rules-expose_submission_data-2020149-29.patch10.07 KBLaz5530
#1 webform_rules-expose_submission_data-2020149.patch4.9 KBAaronBauman
#2 webform_rules-expose_submission_data-2020149-2.patch6.46 KBAaronBauman
#3 webform_rules-expose_submission_data-2020149-3.patch6.43 KBAaronBauman
#4 webform_rules-expose_submission_data-2020149-4.patch6.38 KBAaronBauman
#6 webform_rules-expose_submission_data-2020149-6.patch7.61 KBAaronBauman
#20 webform_rules-expose_submission_data-2020149-20.patch7.66 KBlogaritmisk
#26 webform_rules-expose_submission_data-2020149-21.patch7.8 KBLaz5530
#27 webform_rules-expose_submission_data-2020149-26-27.interdiff.txt703 byteswebflo
#27 webform_rules-expose_submission_data-2020149-27.patch8.16 KBwebflo
#31 webform_rules-expose_submission_data-2020149-28.patch9.2 KBLaz5530
#31 webform_rules-expose_submission_data-2020149-27-28.interdiff.patch2.71 KBLaz5530
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

AaronBauman’s picture

Status: Active » Needs review
FileSize
4.9 KB
AaronBauman’s picture

AaronBauman’s picture

AaronBauman’s picture

Assigned: AaronBauman » Unassigned
Status: Needs work » Needs review
FileSize
6.38 KB
AaronBauman’s picture

Assigned: Unassigned » AaronBauman
Status: Needs review » Needs work

grumble. still doesn't quite work

AaronBauman’s picture

Assigned: Unassigned » AaronBauman
FileSize
7.61 KB

Ready for Review:

penone’s picture

Question - does this patch allow me to choose a field value from my webform submission as a condition.

For example - if the user gives a value of Yes on a question can I now use rules to redirect the user to a different url?

AaronBauman’s picture

yes

HyperGlide’s picture

When adding the new condition "Submission to a particular webform",
I got an error "Unknown condition data_nid."

HyperGlide’s picture

Not trying to highjack the issue just see if my use case matches this patch.

Working with rules and have (2) rules component rules.
They are both (actions) to 1 larger rule that responds to an event - After a webform has been submitted -
- Component 1 - Test to see if the email address in the web form has an account on the site. If YES - Gives Warning to User.
- Component 2 - Test to see if the email address in the web form has an account on the site. If NO - Creates and account and informs the user.

I believe the submitted webform tokens are not being passed to the components for evaluation and action.

A copy of the rule and the components can be found here:

Rule - https://gist.github.com/HyperGlide/1add428b95885dd1a1ff
Condition 1 - https://gist.github.com/HyperGlide/5961d6c752f81848e790
Condition 2 - https://gist.github.com/HyperGlide/4885d7b32ad833e0b1f0

jams1988’s picture

Hey Arron:

I applied the patch, and I am happy that I can get some data like data:name.
But when I tired to use the old token like[data:{component}-title], [data:{component}-value].
I get a error:

Fatal error: Cannot use object of type stdClass as array in /home1/varoon5/public_html/majoreno.com/sites/all/modules/webform_rules/webform_rules.module on line 213

Can we keep the old token available and the new data:xxx in your patch? Thank you~~~

AaronBauman’s picture

Assigned: AaronBauman » Unassigned
Status: Needs review » Needs work

Thanks for the reviews.
I think preserving the old tokens is definitely important.
I hope to have some time to work on this soon, but feel free to pick this up if anyone else wants to.

Juisi’s picture

Hello Dear Community.

Thank you for this important patch!

This is supposed to be additional questioning to: #7 by penone

Question - does this patch allow me to choose a field value from my webform submission as a condition.

For example - if the user gives a value of Yes on a question can I now use rules to redirect the user to a different url?

Sorry if this comment bulks your whole window, i prefer to define the context or the question as well as possible (..and this is my first actual post on drupal.org:)

The patch seems to bring a solution to exactly what i wish to accomplish:
Anonymous users submit their contact info to a ticket ordering system. The webform sends payment info mail to the submitted email address. Works as it should.

At some point the admin manually checks the payments (from a bank web site) and decides to update the order submissions.. 1 by 1.

Rules event: After a webform submission has been updated

(the update is made by admin user, who sets one particular (checkbox) webform field 'varauksen_tila' value from 0 to 1 ..which means that the particular ticket order has been paid. This event is supposed to trigger the action of sending of another email to the user.."thanks for your payment etc"..

the select field is configured with a default value of 0
and the options are defined as key|option pairs:
0|maksamaton
1|maksettu

Rules condition: a field 'varauksen_tila' value == 1 ....proceed to actions

So now the questions:

Question 1. Does the Rules recognize the the above field key as the data:{component}-value or is it the option that should be compared as the data:{component}-value

Question 2. Should i set the condition to 'data comparison' or does some other condition option provide this functionality?

Question 3. Should the data selector be set to data:varauksen_tila-value ..or how is the syntax supposed to work within the patched logic? I'm having a problem to get the rules to recognize or accept any of these added webform components. The data selectors list does not show the component data:varauksen_tila nor does it show any of the other fields which i added to the webform.
Just showing the default lines:
data The submitted webform data
data:sid Submission ID
data:submitted Date Submitted
data:remote-addr IP Address of the submitter
data:uid User ID of the submitter
data:name Username of the submitter
data:is-draft Whether the submission was finalized
form-id The form id of the submitted form
selected-webform Webforms The name of the webform to check for.
selected-webform:0 Webforms The name of the webform to check for.
selected-webform:1 Webforms The name of the webform to check for.
selected-webform:2 Webforms The name of the webform to check for.
selected-webform:3

Question 4.(supposed i get the above working) How can i compare the component value to a fixed value like 1? does the component value need to be numeric before the rules lets to make a direct input mode comparison between the component value and a fixed value ?

Btw. at some point i was seeing the Rules to suggest my custom webform components as data selectors. Unfortunately, i already had messed up the first part of the condition with the generic data selector 'data'. So i deleted the rule to start over but the problem persisted.

Are we looking a bug here or am i just misconfiguring the webform field and/or the Rules condition?

Thank you very much for your patience!
Best,
Jussi

wizonesolutions’s picture

aaronbauman: How's your time atm? Do you know more or less what needs to be done to support the old tokens? I'm not sure if I have time either, but a reader might if a general implementation plan is laid out.

I have used the patch, though, and just wanted to say THANK YOU. Once fully-baked, this patch will make Webform Rules way, way better and more usable.

erc23mohan’s picture

Hi aaronbauman.. your webform_rules-expose_submission_data-2020149-6.patch looks promising. I am eagerly waiting for an update which allows me to compare webform submission fields data to trigger actions. On updating this patch I also got error as in #7. Please update the patch.....

sonicthoughts’s picture

+1 subscribing

sonicthoughts’s picture

Issue summary: View changes

updated to include new info from comment thread

mirsoft’s picture

Issue summary: View changes

The error in #9 appeared to me if I didn't empty cache after applying the patch.

HyperGlide’s picture

@mirsoft thanks for the post.

kevster111’s picture

Is this patch in the current dev? Latest stable release seems to only show webform submission component variables on adding an event. Not allowing those variables use in action. Tried all kinds of conditions. Created node on webform submission works great but only allows title and author variables from webform submission. I would think this patch would solve that. I might be way off though.

logaritmisk’s picture

Status: Needs work » Needs review
FileSize
7.66 KB

Re-roll agains dev and fix Fatal error: Cannot use object of type stdClass as array.

Marc Angles’s picture

Hi, I'm trying this patch (#20) on a prestine drupal install to test it.

As soon as I try to add the conditions "Submission to a particular webform" I have an error "Unknown condition data_nid"

bisonbleu’s picture

Edit: rewrite of my initial post based on new tests on a very basic Webform (webform-7.x-3.20, 7.x-4.0-rc3, 7.x-4.x-dev).

Having major issues with patch in #20: system errors + empty tokens.

Use-case: a simple Webform with 3 fields. Form keys are: first_name, last_name and email. A basic rule. Event: After a webform has been submitted. Conditions: Webform has name (Parameter: The form id of the submitted form: [form_id], Webforms: Webform simple test). Action 1: Show a message on the site. Action 2: Execute custom PHP code: dpm($data);. Here is what I get when I submit this form.

Errors

Notice: Array to string conversion in DatabaseStatementBase->execute() (line 2171 of /Applications/MAMP/htdocs/d7test/includes/database/database.inc).
Notice: Array to string conversion in DatabaseStatementBase->execute() (line 2171 of /Applications/MAMP/htdocs/d7test/includes/database/database.inc).
Notice: Array to string conversion in DatabaseStatementBase->execute() (line 2171 of /Applications/MAMP/htdocs/d7test/includes/database/database.inc).
Notice: Undefined index: components in webform_rules_tokens() (line 213 of /Applications/MAMP/htdocs/d7test/sites/all/modules/webform_rules/webform_rules.module).
Warning: array_keys() expects parameter 1 to be array, null given in webform_rules_tokens() (line 213 of /Applications/MAMP/htdocs/d7test/sites/all/modules/webform_rules/webform_rules.module).
Notice: Undefined index: sid in webform_rules_tokens() (line 216 of /Applications/MAMP/htdocs/d7test/sites/all/modules/webform_rules/webform_rules.module).
Warning: in_array() expects parameter 2 to be array, null given in webform_rules_tokens() (line 228 of /Applications/MAMP/htdocs/d7test/sites/all/modules/webform_rules/webform_rules.module).
Warning: in_array() expects parameter 2 to be array, null given in webform_rules_tokens() (line 228 of /Applications/MAMP/htdocs/d7test/sites/all/modules/webform_rules/webform_rules.module).

Show a message on site

- input: data:sid = [data:sid], data:first_name-title = [data:first_name-title], data:first_name-value = [data:first_name-value]
- output: data:sid = , data:first_name-title = , data:first_name-value =

Devel output

 ... (Object) stdClass

    sid (String, 3 characters ) 137
    nid (String, 2 characters ) 35
    serial (String, 2 characters ) 10
    submitted (String, 10 characters ) 1403631821
    remote_addr (String, 9 characters ) 127.0.0.1
    uid (String, 1 characters ) 1
    name (String, 5 characters ) admin
    is_draft (String, 1 characters ) 0
    preview (Boolean) FALSE
    data (Array, 3 elements)
        1 (Array, 1 element)
            0 (String, 3 characters ) Joe
        2 (Array, 1 element)
            0 (String, 4 characters ) Blow
        3 (Array, 1 element)
            0 (String, 11 characters ) jb@some.com
    35__1 (Array, 1 element)
    35__2 (Array, 1 element)
    35__3 (Array, 1 element) 
bisonbleu’s picture

Update.

Fatal error will occur when tokens listed under Replacement patterns for The submitted webform data are used inside an Execute custom PHP code action e.g. dpm("Data SID: [data:sid]");.

Fatal error: Cannot use object of type stdClass as array in /Applications/MAMP/htdocs/d7test/sites/all/modules/webform_rules/webform_rules.module on line 213

This appears to indicate that there might be a problem with the implementation hook_tokens() in webform_rules.module.

bisonbleu’s picture

Status: Needs review » Needs work

I think the above warrants setting this issue back to 'Needs work'.

This patch looks great and I could sure use its functionalities. Any help in resolving this issue would be greatly appreciated.

bisonbleu’s picture

Issue summary: View changes

small typo

Laz5530’s picture

Status: Needs work » Needs review
FileSize
7.8 KB

Webform vers. 7.x-4.0
Webform Rules vers. 7.x-1.6

I eliminated the bug that caused: "Notice: Trying to get property of non-object in webform_rules_condition_data_nid() (Line 226 of /.../webform_rules/webform_rules.rules.inc)."
So now the condition "Submission to a particular webform" actualy works(until now it always returned FALSE).

I still got 20x "Notice: Array to string conversion in DatabaseStatementBase->execute()" but its ok.

webflo’s picture

  • stBorchert committed 6c65a14 on 7.x-1.x
    Issue #2020149 by grahamC, aaronbauman, webflo, Laz5530, logaritmisk:...
stBorchert’s picture

Status: Needs review » Fixed

Thanks for your work guys. Committed to 7.x-1.x-dev.

melvinlouwerse’s picture

Is this issue indeed ready with the latest patch ?

see comment #23

Fatal error will occur when tokens listed under Replacement patterns for The submitted webform data are used inside an Execute custom PHP code action e.g. dpm("Data SID: [data:sid]");.

When i use the latest patch i still experience that problem.

Laz5530’s picture

Hi,

I experienced the same problem like #30. The cause can be the new verison of Webforms and Ctools.
And also the tokens in E-Mail-Rules didn't worked to me (like #10).

Webform 7.x-4.2, Webform Rules 7.x-1.6, Chaos tools 7.x-1.5 and Drupal core 7.34

I upgraded the patch in #27, changes

  • Fixed "Fatal error: Cannot use object of type stdClass as array in ..."
  • Tokens are now (as before) like [data:COMPONENT] e.g. "[date:e_mail]"
  • Tokens will be replaced (with value as default) in E-Mail-Rules e.g. "[date:e_mail]" --> "example@gmail.com"
  • Tokens in token selector (e.g Datacompare) are now like data:COMPONENT e.g data:e_mail (not like data:32:04)
Laz5530’s picture

Patch upgraded:
Every token should work now. Like [data:e_mail-value], [data:e_mail-title]
I give every argument to the drupal-renderer, so it can do its work.

In version #31 select-field tokens always returned the key and not the value.
E.g SelectField "YesOrNo" (1|Yes; 2|No) with Yes selected
[data:yesorno] was replaced with "1".

stBorchert’s picture

Status: Patch (to be ported) » Needs work

If there is still a problem there is no need to include already committed code in the new patch :)
The patch in comment #2020149-27: Expose submission data to rules is included in 7.x-1.x-dev.

Laz5530’s picture

Status: Needs work » Needs review
FileSize
3.44 KB

Thanks for the hint, here is the rigth patch - without already commited code :)

Exploratus’s picture

I tester #27 and #34, doesn't seem to change anything. Can't see webform data.

Laz5530’s picture

@Exploratus where can't you see webform data?

Here is how it works for me (sorry for my bad english):

  1. You create a webform "WF" with fields "t1"="sometext" and "mail"="example@drupal.org".
  2. You create a rule "R" with event "After a webform submission has been updated".
  3. You set condition "Submission to a particular webform" with parameter "data" and "WF".
  4. You can now use condition "Data comparison" with parameter "data:t1", "equal" and "sometext". Note that for me the dropdown for choose data only works with JQuery update: "Default jQuery Version: 1.5". You can chage it back to 1.10 after done editing your rule.
  5. You can now add an action "Send mail" with parameter "[data:mail]", "Mail from rule R" and "Hello, here is t1: [data:t1]"
  6. After editing a submission to WF example@drupal.org will get a mail with subject "Mail from rule R" and text "Hello, here is t1: sometext"
kevster111’s picture

So what do I need installed to get this to work. Been a bunch of patches so I am a little behind. Latest dev and the patch in 34? Is that all?

Laz5530’s picture

Yeah, latest dev and patch #34. It should be the same as the release 7.x-1.6 and patch #32.
Where can you download latest dev? Under https://www.drupal.org/node/982408/release?api_version%5B%5D=103 I see no dev.

stBorchert’s picture

@Laz5530: if you scroll to the bottom of the linked page you will find the 7.x-1.x-dev release (last but one item).
Here is the direct link to the relases: https://www.drupal.org/node/1114618

kevster111’s picture

FileSize
27.25 KB

Not sure if I should add this as a new issue but I think it relates to this thread or Im just not doing something right. Ive attached an image of my settings. This started happening after the update.

Im not sure that the components are getting evaluated right. I am creating a separate node on webform submission. The node does get created but only the author gets filled correctly as I set it to be admin (1) every time. The title which used to work before I updated to current dev and patch in 34 used to go in correctly but now it just gets output as array (literally) that is the title of the created node after a webform submission.

In the image you can see Ive added fields on webform submission but those have never worked for me anyways so that isn't from the update, I just don't know the correct procedure.

If there is a donation box Id add something for showing me the correct way to do the above. Also Im thinking there is a bug since it used to at least give me the title.

Laz5530’s picture

FileSize
32.56 KB
50.8 KB

@stBorchert: Thanks, found it.

@kevster111: What input mode do you use in Create a new entity/title? If you use direct input mode than [data:first-name:0] is not a valid token. You should use [data:first_name]. Can you try that?

I understand you tried to use that, but the tokens in "data selection" mode are not the same as in "direct input" mode. If you switch to "direct input" mode and open "replacement patterns" you find [data:{component}-value]. You have to replace {component} with the machinereadable-name of the component e.g. [data:first_name] or [data:e_mail].

I attached screenshots from a rule that does what you want and works for me.

kevster111’s picture

@Laz5530: I used both methods. Nothing comes up. I did however try direct input again with value-raw and that seems to work. Going to direct input has now given me the following error thought. But the fields populate. which is better. They do show the extra text though which looks like value:billy or whatever name gets put into the field. I suppose I could rewrite results and strip the value text out but Im thinking I have something wrong.

Tried to remove the raw format and go back to just value and it stopped filling the fields again.

Heres the error I get (haven't looked through this thread for this particular issue yet sorry)
Notice: Undefined index: required in webform_rules_tokens() (line 229 of mysites/sites/all/modules/webform_rules/webform_rules.module).

Should say Im using:
entity --api latest
webform rules --latest dev plus patch
rules --7.x2.3
webform --7.x 3.21 (php ver 5.2 something) cant upgrade currently on that particular server.

Laz5530’s picture

@kevster111: It probably doesn't work for you, because you use old version of modules.
The latest stable releases: Rules 7.x-2.7 , Webform 7.x-4.2. So you should update.

As you can see in #31, I posted this patch because of the new release of webforms, so i don't think it would work with older versions.

If you can't or don't want to update you modules, you can try Webform 1.6 with patch #27 (it should be the same as latest dev) and use tokens like [data:form_id:component_id] e.g [data:13:4]

Exploratus’s picture

I am using latest rules, webform, and dev version of Webform_rules. I applied patch #34. I followed steps in #36, but I am still unable to pull [data:t1] tokens.

When I try to use data tokens from my custom webform fields IN ACTIONS, the data tokens are just not there. The data: -> is empty. My webform fields are just not options on the list. When I try to force it, it says its an invalid parameter.

When I try to use it in CONDITIONS, for data: -> i get submission ID, date, IP, username, etc. But I don't get any of my webform fields.

Any help would be appreciated.

Rosamunda’s picture

I've got it working, but it is a little confusing how to set it up:
I've followed #36, but I'm stuck where you have to actually compare the data.

I have a webform node id: 8350 and a field called: estado, which is a list:

0|pendiente
1|cancelado
2|completado

I want to target people selecting option 3. So I've selected "data comparision".

I have all this data selectors:

data:8350--3	Estado	estado from node 8350
data:8350--3:0	Estado	estado from node 8350
data:8350--3:1	Estado	estado from node 8350
data:8350--3:2	Estado	estado from node 8350
data:8350--3:3	Estado	estado from node 8350

I assume that the field itself is data:8350--3 and the third option is data:8350--3:3.

What should I use as data selector? I've tried data:8350--3 and data:8350--3:3.

And what should I use as data value?
I've read all replacement patterns, and found:
[data:{component}-value] Component value The value of the selected component, e.g. "email-value".

So, I've tried: [data:8350--3-value] and [data:8350--3:3-value]

I keep getting an error when I try to submit the form:
Fatal error: Cannot use object of type stdClass as array in /home/sitio/public_html/sites/all/modules/webform_rules/webform_rules.module on line 213

Thanks for your help!

bisonbleu’s picture

I have a similar issue as @Exploratus in #44.

[SOLVED]

  • rules-7.x-2.8 (also works with 7.x-2.3)
  • webform-7.x-4.2
  • webform_rules-7.x-1.6+3-dev, patched with webform_rules-expose_submission_data-2020149-30.patch

BEFORE (problems)

  • In the data selector I have access to all Webform field tokens i.e. [data:full-name], [data:title], etc.
  • But if I create a condition such as [data:full-name], Data value: some_name, I see the following error in the Rules evaluation log: Unable to apply data selector data:full-name: Unknown data property full_name.
  • And if I use those tokens in a system message they all return ' ' (empty strings); and [data:data] returns false.

AFTER (solution)

  • I was using the wrong tokens i.e. [data:full-name] instead of [data:full_name-value].
  • If your component name is My precious field, its machine name will be my_precious_field and therefore your token will be [data:my_precious_field-value]. So watch out for underscores and don't forget to add 'value'.
  • Bonus: print $data->full_name[0]; is the same as [data:full_name-value]

This is one very useful module. Thanks to all!

Laz5530’s picture

@Rosamunda: In data-comparison use data:8350--3:0 = 2 or data:8350--3:0 = completado (i can't test it right now but one of them will work).
For showing the value of field use [data:estado-value].

@bisonbleu: I'm happy that you got it working. And yes you have to use the machine-name, sorry if i wasn't clear about it before. Machine readable name always uses underscores for extra characters.

I'm not working anymore on the project, but i help if i can.

bisonbleu’s picture

I'm not working anymore on the project, but i help if i can.

That's much appreciated @Laz5530 !

  • stBorchert committed 42a1801 on 7.x-1.x authored by Laz5530
    Issue #2020149 by Laz5530, aaronbauman, webflo, kevster111, logaritmisk...
stBorchert’s picture

I've committed the patch from comment 34 (with some fixes). Please test and review.

4aficiona2’s picture

Which was the last patch which got applied to the latest dev release? #34?

I use Webforms 7.x-4.5 and Rules 7.x-2.9.

I have troubles with the latest dev release of webform_rules and it seems that neither of my token [data:festivalpass_email] nor [data:festivalpass_email-value] get evaluated when I want to create a new entity (user).

Before upgrading to the dev release I used the 7.x-1.6 release and evaluated them with PHP like this: print $data['components']['festivalpass_email']['value'][0]; This worked for simple textfields but I could not figure out how this works with select lists and file fields.

When I used the above PHP code (which worked for 7.x-1.6) I get the following error:

Fatal error: Cannot use object of type stdClass as array in .../docroot/sites/all/modules/contrib/rules/modules/php.eval.inc(125) : eval()'d code on line 1

Any hints?

4aficiona2’s picture

I figured out why I got the Fatal error

Fatal error: Cannot use object of type stdClass as array in .../docroot/sites/all/modules/contrib/rules/modules/php.eval.inc(125) : eval()'d code on line 1

Data now seems to be an object with a data array which is again an array but does not anymore use the machine_name as key like with 7.x-1.6.

Don't really know when what to expect.

When I use

  dsm($data);

sometimes the components are available with their key and sometimes not as you might see in the uploaded images.

I also have a multilang setup like bisonbleu mentioned where the tokens do not work or are actually empty strings. But I don't use webform_localization so far ... but webform_hints and webform_phone.

4aficiona2’s picture

4aficiona2’s picture

Downgraded to 7.x-1.6 release and try to go as far as possible with PHP code like below

 print $data['components']['festivalpass_email']['value'][0]; 
lex0r’s picture

I couldn't make the latest dev (with patch from #33 committed) work for me - tokens were not available because of different argument format expected by webform_rules_tokens. See the patch, it may help if you have the same issue.

lex0r’s picture

A better patch (no notice when invoked natively from a rule, not rule component)

Sansui’s picture

Have tried latest dev, 1.6 + patches, dev + patches

No combination I've tried allows the "Submission to a particular webform" condition to see the submission data.

I get this kind of error message "Data selector data:email for parameter webform is invalid". The "data:" option shows up in the dropdown, but not in the data selectors fieldset

mywebmasteruk’s picture

I have the same issue as #57, any updates?

Dubs’s picture

For me I had to change another line (apologies - making a patch from here is tricky).

Change line 496 of webform_rules.rules.inc from: -

$s = current($s)

to

$s = reset($s)

It looks like the pointer is out on the array - reset just uses the first (and only) item in the array regardless.

selfuntitled’s picture

I'm getting Fatal error: Cannot use object of type stdClass as array in ~/public_html/sites/all/modules/webform_rules/webform_rules.rules.inc on line 226 with the current dev snapshot, which I think includes all (or almost all) the patches above, along with current versions of Rules and Webform.

The problem is triggered when you try to have two rules that apply to the same webform.

When you do this - when webform_rules_condition_data_nid() is called, it's passed $submission as an object instead of an array, which causes the if( empty() to fail.

It looks like this may be a simple patch, will try to turn something around tonight.

selfuntitled’s picture

The attached patched should resolve the error I was getting in #60.

Webform_Rules_Condition_Data_NID is called every time a rule is testing which webform form is being submitted.
Except, the second time it's been called, the outer array around $submission has been stripped off leaving only the contained object.
This patch just tests the type of $submission and interacting with it accordingly and then dropping nid into a variable so it's accessible in the rest of the function.
While I'm at it, looks like the last few lines of this function are useless, as we're never defining $selected_webform, so I removed those.

pauldolphin’s picture

I tried apply the patch in #61 on the latest dev version but I am still not having luck being able to use webform data in the rule I have created. I am attempting to use submission data to populate fields in a newly created node upon form submission.

EVENT: After a webform has been submitted
CONDITION: Submission to a particular webform (rules log show this passes as true as expected and fires the first action in my rul)

ACTION: Fetch webform submissions
node:nid (this appears to be working)
data:sid (continues to produce and error in the rules evaluation log "The variable or parameter sid is empty.")
This produces another error in the rules evaluation log: "Unable to evaluate action webform_submissions_load"

I've tried to simply print a message with the sid or values in using both token replacement and php but nothing is displayed. Everything continues to be empty.
[data:sid] [data:email-value]
print $data['sid'];
print $data['components']['email']['value'][0];

I came across this other similar issue. I did not have WFM (Webform Multiple) enabled but did have webform_multiple_file enabled so I disabled that in the event that this file module was messing things up. I tried the fixes recommended on this other issue on a clean version of the webform module and a dev version... this did not help either.
https://www.drupal.org/node/2270111

I've tried adding dpm($data); as an action using execute custom php code and as a message... but this produces nothing (yes I have devel enabled.)

When I am in the rule... I have the ability to use the data selector to select these $data related fields. I see these $data related tokens in the replacement tokens dropdown. But... everything I try is just empty. I am unable to fetch the most recent form submission after it has been saved. I am unable to create a new node and use webform submission data to populate this new node's fields.

Anyone else still experiencing issues? Any help would be GREATLY appreciated. I have hit a brick wall and could REALLY use some help.

rooby’s picture

Status: Needs review » Needs work

What version of the module was the patch in #61 made for?
Not latest stable or dev.

Ubiquitous’s picture

Hello, everybody.
Please describe me how I should apply patches:
* everyone - one by one
or
* only the latest patch is enough?

By the way I can confirm that #61 could not be applied for 7.x-1.6

bisonbleu’s picture

@Ubiquitous,

You can see in #50 that the patch from comment 34 was committed (with some fixes). 'Committed' means that this code is in the dev version; you should first try it and see if it works for you. The good news is: no patching is required.

But if you're still having problems with the current dev, carefully read the comments starting at #51 to find out what you should do and/or try for your use case.

About patching, Google drupal how to apply patch and you should find plenty of help, including videos.

Good luck!

smurfxx’s picture

Where can I find the dev version?

rooby’s picture

As far as I can tell this isn't fully fixed and the patch in #61 don't apply to latest stable or dev.

I cannot remember if I have tried the patch in #56 yet.

xenophyle’s picture

The code in the dev version isn't working for me at all when I try to use the condition "Data Comparison" on a field from a Webform. I get the same error described in comment #57.

When I follow along in a debugger it looks like the code in class WebformRulesSubmissionWrapper is expecting $data to be an actual submission, which doesn't exist while you are still setting up the rule. Ideally, you would have set a previous condition specifying which Webform the rule cares about, and then $data would include a list of fields for that Webform, not the submission.

If I had any idea at all how to fix that, I would.

sthomen’s picture

In case anyone came to this issue as a rules novice like I did, there is a possible workaround to use the webform rules without having the values exposed (as this issue is for).

You can initialize a rules string variable with the tokens. If you need integers or booleans you can subsequently convert it to whatever and then use it to load nodes or whatever.

Hope this saves someone some hair-tearing.

bisonbleu’s picture

Doing this in Rules is proving difficult & complicated.

The easy fix for me was implementing hook_webform_submission_presave() in a custom module. Here is the suggested code copied from /sites/all/modules/webform/webform.api.php. Works like a charm.

/**
 * Modify a Webform submission, prior to saving it in the database.
 *
 * @param $node
 *   The Webform node on which this submission was made.
 * @param $submission
 *   The Webform submission that is about to be saved to the database.
 */
function hook_webform_submission_presave($node, &$submission) {
  // Update some component's value before it is saved.
  $component_id = 4;
  $submission->data[$component_id][0] = 'foo';
}
j9’s picture

Does anyone know if this feature has been incorporated into the Webform Rules module?

Or is everyone still using the workaround? Thanks!