I could use a bit of enlightenment when it comes to using rules to add someone to a mailing list. Specifically when someone submits a webform on the website, I would like to use an email field I have on that webform to be used to add to the mailing list. I'm by no means a rules novice, but I'm somewhat confused by what is required in the subscribe to mailchimp mailing list action.

Specifically:

Entity: The entity to subscribe or unsubscribe. I'm assuming this is referring to the entity that is pertaining to the email address. If that is so, it does not appear that the webform data is available as a data-selector for this. Will this not work for webform data? Do I need to be using entity forms?

and...

Mailchimp List subscription field: It would appear that this is for the specific mailing list that one would want to subscribe to, I'm really not sure what format the mailing list should be in. Machine name? List ID?

Thanks for any help and clarification on this. i can't seem to make sense of it, and I've read some other posts on the subject, and it seems that most of what i'm finding does not seem to apply.

Comments

gb2world’s picture

I am also having trouble with this.

I am trying to use the action "Subscribe or unsubscribe entity from mailchimp list"

I set up a simple webform with an email component field key named email_abs

I cannot seem to find data selectors for the "The entity to subscribe/unsubscribe" and the "Subscription Field connected to the desired Mailchimp List" that will work. I have tried data:email_abs-value, selected-webform:data:email_abs-value for the subscribe - which is the email I collected on the web form. I tried adding a hidden field to the webform with an mail list id. I am not sure how else the correct list gets selected? But I cannot get any tokens to work anyway.

Here is my exported rule - I know it is firing, and I am able to get to the webform data using php in the messages, I just cannot figure out how to get the tokens to work for data selectors. Any hints would be appreciated:

{ "rules_mc_for_abc_chi" : {
    "LABEL" : "MC for ABC CHI",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "webform_rules", "php", "devel" ],
    "ON" : { "webform_rules_submit" : [] },
    "IF" : [
      { "webform_has_id" : {
          "form_id" : "[form-id:value]",
          "selected_webform" : { "value" : { "webform-client-form-61" : "webform-client-form-61" } }
        }
      }
    ],
    "DO" : [
      { "drupal_message" : { "message" : "the rule worked!\r\n\u003Cp\u003E1: \u003C?php print $data[\u0027sid\u0027]; ?\u003E\u003C\/p\u003E\r\n\u003Cp\u003E2: \u003C?php print $data[\u0027components\u0027][\u0027email_abs\u0027][\u0027value\u0027][0]; ?\u003E" } },
      { "devel_debug" : { "value" : [ "data" ] } }
    ]
  }
}
joegl’s picture

I guess maybe this rule isn't operating how we all think it should. My best guess, and I cannot find documentation of this anywhere, is that you are correct in assuming the "Entity" field is for picking the Entity that has the email address. However, the next field is looking for a "Subscription Field connected to the desired Mailchimp List." I believe you specifically need a field that is of the field type "Mailchimp Subscription" selected here otherwise it will not work, but do not take my word for it.

My next step is going to be creating a content type that has a "Mailchimp Subscription" field. Then, when a webform is saved, I'll create a new node of that content type and add the email address from the form into the "Mailchimp Subscription" field (this is the step I don't know if I can do). Then I will save that node, and use the "Mailchimp Subscription" field from that node to subscribe the user.

Wish me luck (assuming my assumptions are correct).

joegl’s picture

It seems I have the right idea. To pull the info from the form you'll need to use PHP and the $data variable. I echo out my form fields into the value slots in rules like so:

echo $data['components']['e_mail_address']['value'][0];

I haven't gotten anything to subscribe yet but that appears to be an issue with the Mailchimp and separate from this.

So to clarify I:

1. Created a new content type with a Mailchimp Subscription field (configure to setup with lists and whatnot how you like)
2. Added an Email field to the content type
3. Setup the Mailchimp Subscription field to use the Email field as the email for the subscript
4. Using rules, when a webform is submitted I create a new node of the content type I created, and then fill in the fields with the form data
5. I then save the node to make sure the data is all there
6. I then use the subscribe rule and select the appropriate fields from my content type

I will let you know once I get this to work. I wish there was a simple Rule Action that could simply subscribe an email address to a list but hey, I can't complain. Great module.

joegl’s picture

Coming back to confirm that what I setup worked. Please respond if you need more details, I don't have time now but if you'd like I may be able to come back later and give more detailed info on my setup. Thanks.

butteryak’s picture

I love creative drupal solutions. I could see how this might work, although If I understand you correctly, you are creating a new new node, when a webform is submitted, that seems like a lot of extra nodes created. Perhaps I am miss-understanding.

joegl’s picture

Haha, no you're exactly right. I tried throwing a delete entity action on to the end of the rule set but I couldn't get it to delete the node. Instead I created a new rule that runs on cron and deletes all nodes of the content type I'm using for the subscriptions. It's not ideal, but it was the solution I was able to come up with.

butteryak’s picture

One does what one needs to do, good on you for figuring out a creative way to make it work. I'll be looking into exploring some options soon, I'll post what I find. Thanks for your input.

CountPacMan’s picture

Status: Active » Postponed (maintainer needs more info)

I hope I'm understanding your question. It has been a while and I hope you have got it working, but just in case, this answer is pretty much straight from the documentation. You need to start with an Entity type that has an email address field and a field to the entity type of the type "Mailchimp Subscription". There is a single Rules action to subscribe or unsubscribe Entities with a configured Mailchimp Subscription field. Create a Mailchimp Subscription field on Users and hide the field from them in the UI, then create a rule that subscribes users to this list when they are saved. Here's the example Rules configuration from the documentation. This assigns based on Role "3" and targets a field called field_members:

{ "rules_member_subscriptions" : {
"LABEL" : "Member Subscriptions",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules", "mailchimp_lists" ],
"ON" : { "user_presave" : [] },
"IF" : [
{ "user_has_role" : { "account" : [ "account" ], "roles" : { "value" : { "3" : "3" } } } }
],
"DO" : [
{ "mailchimp_lists_user_subscribe" : {
"entity" : [ "account" ],
"field" : [ "account:field-subscribers" ],
"subscribe" : 1
}
}
]
}
}

Please let us know where you are with this and we can go from there.

millionleaves’s picture

I'm unsure why you need a rule for this. If you have the Webform Mailchimp module, you can then add a new Mailchimp component to your form which handles everything for you.

https://www.drupal.org/project/webform_mailchimp

You can use it to submit merge fields and interest groups to the Mailchimp list you specify. All you need is an email address in the form. You can make the "Subscribe?" checkbox visible or not visible, set or not set.

ruscoe’s picture

Status: Postponed (maintainer needs more info) » Closed (won't fix)

We're going to be ending support for the 7.x-3.x branch due to the upcoming deprecation of the v2.0 MailChimp API. If you're still seeing this issue with the most recent release, please feel free to reopen for the 7.x-4.x branch.