4

I want to send an email when a user fills in a webform, but only if it is our review form and if the user gave the feedback higher than a 7.

So we are asking how good we are, and the user gives us a value from 1 - 10, we want to send an email if that number is higher than 7.

Basically, I have installed the Rules and the Webform_rules modules. Now I can make a rule with an action: 'After a form has been submitted'

Next I made the nid equal to the nid of the specific webform. And then I want make a second condition to compare the filled out value the be 7, 8, 9, or 10, so I make an data comparison condition. With the condition 'data' and the field name like: 'data:grade-value-raw' it just tells me there is no grade-value-raw

If I set the reaction to display the [data:grade-value-raw] on the page, it works.

Why can't I use it in the Rules Condition?

3 Answers 3

3

The "clue" to what you're trying to get to work, is that you 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

So in your case, you should be able to get it to work using something like [data:grade-value].

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.

The above is a good start, but not sufficient to achieve your goal (= validate "... a second condition to compare the filled out value the be 7, 8, 9, or 10, so I make an data comparison condition", as in your question). 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 (yes, "Rules Action", not "Rules Condition" ...) to Add a variable, with a value assigned to it equal to your [data:grade-value-raw] (and with a data type which is probably integer).
  • Use the Conditional Rules module to perform the data comparison as in your question (if it is 7, 8, 9, or 10). However, in this data comparison you now refer to the value of the variable you just added (that's the clue!).

In this answer I'm using the Conditional Rules module, though you could also rework the Rules Action to performing Rules Components (in which you add the appropriate Rules Conditions), so that you don't need this extra module. For more details on that, refer to the answer to "What's the alternative to using the Conditional Rules module?".

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

2

This doesn't answer your question directly but it's an alternative solution. You could do this without rules and just with webforms, assuming your rating in a select box.

In the emails section when editing the webform, rather than entering an email address you can select the "Component value". Choose your select box and then enter your email address for values 7, 8, 9 and 10.

That should only email if those values were selected

1

Add the condition in the rule using Conditional rules (rather than the conditional state itself). I've found that in many cases the conditional state of a rule can't always access the data of a form (entity forms same deal).

Create a If [fieldname] is greater than condition and it should work for you.

1
  • Hey Rob, your last phrase is usually the correct approach ... if you'd be dealing with regular entities. However, Webform is special, and you won't be able to add such conditions that refer to values of the specific Webform component (try it if you don't believe me). The only way to get that to work, is using a (silly?) workaround as explained in my own answer ... Nov 21, 2017 at 10:16

Your Answer

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

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