1

Is there a way for the user to opt in/out of receiving an email upon the triggering of a rule?

I have a rule to send an email to the author of a node any time a new node is created which references it. This is done in the following way;

ON event After saving new content IF Created content is published

DO actionLoad a referenced node actionLoad the Referenced content author actionSend a mail to a user

Unfortunately the author of the node has no way to opt out of receiving the email. Any idea how I can make the sent email conditional upon it being flagged first? Or better still, is there a way I could place a checkbox in the original node creation form where the user can opt in or out of receiving these notifications? Or maybe someone has some other ideas? Another module perhaps...?

1
  • I'm dont use rules much so i cant say. However this would be easily accomplished with a custom module that just allows the user to opt out. Apr 16, 2012 at 3:27

1 Answer 1

2

One solution is to indeed include a new field, a checkbox on the original node which authors can modify to opt in or out of the emails. You can set the field as hidden in the 'Manage Display' tab.

Then, simply edit your rule by adding a condition of type 'Data value is empty' so you can check whether the new checkbox is checked or not. When setting up that new condition, type in 'node:' and then select the new field in the data selector and make sure to check the 'Negate' button if appropriate (based on how you've set up the language on the checkbox: i.e. does checked mean to opt in or opt out by default). If the checkbox says 'Opt in', then a checked value would return false for empty, so you should negate it in the condition.

That should now fire up the rule based on the new field!

3
  • Hi Boriana, I added a checkbox field to the node-type with these allowed values; unsubscribe|uncheck to unsubscribe. subcribe|Check to subscribe and receive email when someone replies to this segment. I didn't see an option for "Data value is empty" in rules. Should I have checked "field has value" instead? I am using Drupal 6 and rules 6.x-1.4.
    – Meggy
    Apr 28, 2012 at 17:04
  • Also if the the rule is being executed on the referencing (child)node, how do I check that the "Data value is empty" for the original referenced (parent) node?
    – Meggy
    Apr 30, 2012 at 7:22
  • Meggy, I didn't realize you were using Drupal 6. I, myself, am using Drupal 7. You're right in your second comment that you want to check a field that exists in the referenced node, not the one that triggers the rule. Why don't you test out the 'field has value' option Drupal 6 rules gives you. Just make sure when you're specifying the field, to first type in 'node:' and then select the referenced field, and then see if the checkbox field attached to that is an option you can choose. Does this make sense?? Apr 30, 2012 at 14:49

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.