send array of checkbox values to mailchimp via mailchimp api 2.0

倾然丶 夕夏残阳落幕 提交于 2019-12-12 01:03:19

问题


I'm using this Mailchimp 2.0 PHP wrapper:

https://github.com/drewm/mailchimp-api

To send data to my list via the Mailchimp 2.0 API.

I can get email, firstname, and lastname to send successfully from my form to mailchimp.

I set those up as required fields in mailchimp(EMAIL, FNAME, LNAME).

Here is the PHP for that:

$MailChimp = new MailChimp('xxxxxxx');
$result = $MailChimp->call('lists/subscribe', array(
'id'                => 'xxxxxx',
//required fields
'email'             => array( 'email' => $_POST['email']),
'merge_vars'        => array('FNAME' => $_POST['fname'], 'LNAME' => $_POST['lname']),
//mailchimp options
'double_optin'      => false,   
'update_existing'   => true,
'replace_interests' => false

));

But I also have 12 checkboxes for stuff like engine size, type, gas type, color, etc. that are optional.

How can send these to the mailchimp API? I'm hoping someone with experience with Mailchimp API could help out.

Any help would be appreciated.

Thanks!


回答1:


Here is a clarification to the structure of the groupings that is not in the docs' example. I.e. you supply only the names of the groups that have been selected by the user:

"merge_vars": {
       "groupings": [
           {
               "groups": [
                   "selection 3",
                   "selection 7"
               ],
               "id": <group_id>// or "name": <group_name>
           }
       ]
   },



回答2:


In the merge_vars array, define "groupings" which points to an array. This 'groupings' array will then consist of individual arrays that point to a particular grouping of groups. Ex. if you have a grouping of groups titled "gas type" with group options "diesel", "unleaded", etc. this level of the array points to "gas type".

THEN, you define a "groups" array inside of this array to denote membership into the actual subgroups ("diesel", "unleaded").

Here's a code example from the list subscribe MailChimp API 2.0 documentation:

"merge_vars": {
        "groupings": [
            {
                "id": 42,
                "name": "example name",
                "groups": [
                    "..."
                ]
            }
        ]

lists/subscribe: http://apidocs.mailchimp.com/api/2.0/lists/subscribe.php

My personal suggestion: create groups in the web app if you haven't already. Then, use the lists/interest-groupings method to see how the interest groups are formatted and returned to you. This gives you a sense of how to structure it in your own code.

lists/interest-groupings: http://apidocs.mailchimp.com/api/2.0/lists/interest-groupings.php



来源:https://stackoverflow.com/questions/21617934/send-array-of-checkbox-values-to-mailchimp-via-mailchimp-api-2-0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!