2

I am working on a site that has a registration form (created with Webform) for 4 different conferences.

The registration goes to everyone on the list (there are 8 people on the email list). But we just added another conference that should only go to 3 people in particular.

Is there a way, to write a rule (we have custom ruleset module) to have the registration email for a particular conference go to a specific person? I am working on Drupal 7.

Any suggestions would be greatly appreciated.

  • How is that registration form implemented, are you using webform for that? And what are the criteria to differentiate the form of one conference from another one? Also, what do you mean by that "we have a custom ruleset module", and how is it relevant to your question here? – Pierre.Vriens Dec 21 '17 at 14:14
  • The form was created with Webforms. There are 4 different conferences. The registration goes to everyone on the list, but we just added another conference that should only go to 3 people in particular. I was wondering if there was a way to right a Rule for that. But, we don't have the Rule Module. But, we do have Custom Ruleset Module. I've never used that before and whenever I did a search for help with that, the Rules module is what comes up. I think it's a predecessor to the Rules module. – William Hodge Dec 21 '17 at 14:30
  • you partially answered my prior comment, and I integrated relevant info in your prior comment into your question (please review/correct if needed). What is the URL of that "custom ruleset module" on Drupal.org? I doubt it's a contributed module, is it? And what are the criteria to differentiate the form of one conference from another one (as in my prior comment)? – Pierre.Vriens Dec 21 '17 at 14:55
  • When I do a search on Drupal for Custom Ruleset, nothing comes up. It must be a custom module. Here is the link to the form: fletc.gov/ogc-training-programs/register. There are four programs. When you register for them, the email goes to a group of people. The last one L&E, when you register for that one, the email has to go to 3 people are particular. Not everyone on the list. Does this help, seeing the form? – William Hodge Dec 21 '17 at 15:47
  • Some day that link in your prior comment may stop working, so please include whatever you think is relevant about that form (in the context of your question), into your actual question. Apart from that, I'm curious to hear how close I am with the answer I just posted, more or less around the time you posted your prior comment. Not sure it my answer is complete, but it should be pretty close already (and note: no need for whatever custom module). – Pierre.Vriens Dec 21 '17 at 15:58
2

There doesn't seem to be a "custom ruleset" module on Drupal.org, but I'd simply use the Rules module, together with the Webform Rules module, as further explained below.

Step 1 - Create a basic eMail about the submitted 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" : [] },
    "IF" : [
      { "data_is" : { "data" : [ "form-id" ], "value" : "2" } },
      { "user_has_role" : {
          "account" : [ "site:current-user" ],
          "roles" : { "value" : { "2" : "2" } }
        }
      }
    ],
    "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" : [ "" ]
        }
      }
    ]
  }
}

Some details about the above rule:

  • Rules Event: After a webform has been submitted
  • Rules Conditions:
    • Form-id has value "2" (change to whatever form-id to fit your case).
    • User submitting the form is logged in.
  • Rules Action: Sent an eMail.

Not sure if it is the case for you, but if the user who submitted the form is authenticated (not anonymous), then you do already 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]. If the user is anonymous, just omit that condition, and don't refer to those tokens in the eMail being created.

Step 2 - Include data from the submitted Webform data in your eMail

You do have access to all labels and all values of any field of a Webform, ie:

  • [data:MachineFieldName-title] contains the Label of a field with machine name MachineFieldName.
  • [data:MachineFieldName-value] contains the Value of a field with machine name MachineFieldName

For way more details on this, and a prototype rule about this, refer to the answer to "How to create a node from a Webform using rules?":

  • the 1st attempt relates to using "Entity has field" (which doesn't work for Webform).
  • the 2nd attempt explains what to do in case of Webform.

And while the above is a good start, it may still not be sufficient to achieve your goal. I.e. if you want to use specific data from the submitted webform. However, you can 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 [data:SomeField-value-raw] (and with an appropriate data type). I'm assuming a field in your webform has a machine name like SomeField (adapt to fit your machine name).
  • In your subsequent Rules Actions you can refer to the value of this variable you just added (that's the clue!).

Step 3 - Cover all possible variations of the Webform data

To make this work for each of the 4 (or 5?) conferences, you basically have 2 options:

  • Duplicate this rule for each possible form id (or form component value if all conferences are covered via a single form) you want to process this way. E.g 1 such rule for each conference.
  • Use the Conditional Rules module if you want to have a single (consolidated) rule for all conferences to be processed.

Here is an example rule (in Rules export format), which uses the Conditional Rules module:

{ "rules_process_submitted_webform_based_on_a_component_value" : {
    "LABEL" : "Process submitted webform based on a component value",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "rules_conditional", "webform_rules" ],
    "ON" : { "webform_rules_submit" : [] },
    "IF" : [
      { "data_is" : { "data" : [ "form-id" ], "value" : "2" } }
    ],
    "DO" : [
      { "variable_add" : {
          "USING" : { "type" : "text", "value" : "[data:somefield-value-raw]" },
          "PROVIDE" : { "variable_added" : { "submitted_form_component_value" : "Submitted form component value" } }
        }
      },
      { "SWITCH" : {
          "USING" : { "data" : [ "submitted-form-component-value" ] },
          "DO" : [
            { "CASE" : {
                "USING" : { "value" : "1" },
                "DO" : [ { "drupal_message" : { "message" : "Webform Option 1 was selected" } } ]
              }
            },
            { "CASE" : {
                "USING" : { "value" : "2" },
                "DO" : [ { "drupal_message" : { "message" : "Webform Option 2 was selected" } } ]
              }
            },
            { "CASE" : {
                "USING" : { "value" : "3" },
                "DO" : [ { "drupal_message" : { "message" : "Webform Option 3 was selected" } } ]
              }
            },
            { "DEFAULT CASE" : [
                { "drupal_message" : { "message" : "Webform Option selected was different from 1, 2 and 3" } }
              ]
            }
          ]
        }
      }
    ]
  }
}

Some details about the above rule:

  • Rules Event: After a webform has been submitted
  • Rules Condition: Form-id has value "2" (change to whatever form-id to fit your case).
  • Rules Actions:

    • Add an extra Rules Action to Add a variable, with a value assigned to it equal to your [data:SomeField-value-raw] (and with an appropriate data type). I'm assuming a field in your webform has a machine name like SomeField (adapt to fit your machine name).
    • Show a message on the site (depending on the value of the variable that was added via the prior Rules Action).

What is left to do to further tune the above Rules example to fit your needs:

  • Replace the "Show a message on a site" by an appropriate eMail to be created (for each "case").
  • And for each of those eMails just indicate which eMail Ids should receive that eMail.

Voilà

PS: forget about your "custom ruleset module", no more need for it to solve this challenge.

| improve this answer | |
  • This sounds like a pretty good solution. Let me try it out and I'll let you know how it goes. Thanks for you help. – William Hodge Dec 21 '17 at 16:30
  • yes, your solution worked great. Thank you for your help. This forum and the people on it are fantastic. – William Hodge Dec 29 '17 at 11:27
  • @WilliamHodge merci for the accept, and upvote. Next question? – Pierre.Vriens Dec 30 '17 at 13:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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