2

I am using the Webform Rules module and I created an event 'After submitting webform', and an action 'Fetch webform submissions'.

When I add an action 'Show a message on the site', I get all the webform data values and I can print them out in status message.

Now I want to Get the user ID who submitted the webform to send that user a private message (about the form data). But when I add an action 'Fetch entity by ID', I get no webform data values there (I'd like to use a data value as entity ID).

Am I missing something, is this the right way to achieve this ? Any other idea on how to do this please?

1 Answer 1

0

Using the Webform Rules module is indeed part of the puzzle to answer your question, as you can read also on its project page:

This module adds rules integration on webforms.

Did you ever want to react on webform submission using rules but couldn't find the proper event?

Webform Rules makes it possible to catch webform submissions by rules and do whatever you'd like to do with it (meaning: do whatever rules let you do with it).

1. Get the user ID who submitted the webform

Have a look at this example rule (in Rules export format):

{ "rules_process_submitted_webform" : {
    "LABEL" : "Process submitted webform",
    "PLUGIN" : "reaction rule",
    "ACTIVE" : false,
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "webform_rules" ],
    "ON" : { "webform_rules_submit" : [] },
    "DO" : [
      { "mail" : {
          "to" : "[site:mail]",
          "subject" : "A new webform submission has occured",
          "message" : "A new webform submission has occured (with form-id \u0022[form-id:value]\u0022). It was submitted by the user with id = [user:id], name = [user:name] and eMail Id = [user:mail] ...",
          "language" : [ "" ]
        }
      }
    ]
  }
}

I intentionally did not include any Rules Conditions here, just to illustrate that by using the Rules Event you're already using, you do have access to a limited set of tokens related to the user who submitted the webform, such as [user:id], [user:name] and [user:mail]. In other words, you don't need a Rules Action like "fetch entity by ID" for these kinds of tokens to be available.

Of course, because of the nature of your question, you may want to add a Rules Condition to check that the user is not an anonymous user.

2. About the Webform data

The "Webform data"-part of your question seems like an example (variation?) of what's asked for in the feature request "Expose submission data to rules". Here is a summary of it:

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.

Issue status is "Needs work" ... not an "easy" issue though.

The very same issue contains a comment with a workaround (it's genious I think, because it's so simple), here is a relevant quote from it:

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.

A picture is worth more then 1000 words: checkout the screenprint included in that comment.

So you could use a technique similar to what is described in my answer to "How to do a data comparison to submitted webform data when using the Rules module?". For short:

  • Add an extra Rules Action to Add a variable, with a value assigned to it equal to your Webform data you want to use (and with an appropriate data type). You'd need 1 such variable for each Webform component for which you want to access its Webform data.
  • In your subsequent Rules Actions you can refer to the value of these variables you just added (that's the clue!).

PS: I'm assuming this question is about D7.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.