2015-07-10 41 views
1

我被困在如何檢索和發送使用API​​ 2.0的Mailchimp表單中的複選框的值。 在我的形式結束時,我有這個複選框Mailchimp API 2.0訂閱用戶與組 - 複選框值

<input type="checkbox" checked data-dojo-type="dijit/form/CheckBox" id="group_1" name="group[4909][1]" value="1" class="av-checkbox"><span id="message-check">YES, I agree to be contacted by ... for promotions and special offers.</span> 

這裏我的PHP代碼連接,並通過API發送數據:

$email = array('email' => htmlentities($_REQUEST['MERGE0'])); 
$merge_vars = array(
'MMERGE3' => $_REQUEST['MERGE3'], //Voucher value 
'MMERGE4' => $_REQUEST['MERGE4'], //Date value 
'MMERGE6' => $_REQUEST['MERGE6'], //Sales Person value 
'FNAME' => $_REQUEST['MERGE1'], //First Name value 
'LNAME' => $_REQUEST['MERGE2'], //Last Name value 
'MMERGE5' => $_REQUEST['MERGE5'], //Phone value 
'groupings' => array(
    'id' => '4909', 
    'name' => "Offers", 
    'groups' => $_REQUEST['group'] 
    ) 
); 
require('Mailchimp.php'); 
$Mailchimp = new Mailchimp($api_key); 
$Mailchimp_Lists = new Mailchimp_Lists($Mailchimp); 
$subscriber = $Mailchimp_Lists->subscribe($list_id, $email, $merge_vars, $email_type, $double_optin); 

我跟着這個文檔https://apidocs.mailchimp.com/api/2.0/lists/subscribe.php

所有領域憑證,日期,銷售,名字和姓氏以及電話將被髮送,並且用戶在我的列表中被訂閱。我缺少的唯一值是複選框。我想至少發送「是」或「1」到該複選框的列表中。 想不通!

任何建議傢伙?

謝謝。 文斯。

回答

1

確定發佈我的問題1h後,我發現解決方案。

這裏正確的代碼爲我的作品:

$merge_vars = array(
'MMERGE3' => $_REQUEST['MERGE3'], //Voucher value 
'MMERGE4' => $_REQUEST['MERGE4'], //Date value 
'MMERGE6' => $_REQUEST['MERGE6'], //Sales Person value 
'FNAME' => $_REQUEST['MERGE1'], //First Name value 
'LNAME' => $_REQUEST['MERGE2'], //Last Name value 
'MMERGE5' => $_REQUEST['MERGE5'], //Phone value 
'GROUPINGS' => array(
    0 => array(
     'id' => '4909', // need grouping ID 
     'groups' => array('YES, I agree to be contacted by ... for promotions and special offers.') 
    ) 
), 
); 

換句話說,我打印出來我的組ID,我有我的列表:

//Print the current group of a list 
/*$current_groupings = $Mailchimp->call('lists/interest-groupings', array(
      'id' => 'your_list_ID', 
     )); 
var_dump($current_groupings);*/ 

我組的整個陣列:

array(1) { 
[0]=> array(5) { 
    ["id"]=> int(4909) 
    ["name"]=> string(6) "Offers" 
    ["form_field"]=> string(10) "checkboxes" 
    ["display_order"]=> string(1) "0" 
    ["groups"]=> array(1) { 
     [0]=> array(5) { 
      ["id"]=> int(17445) 
      ["bit"]=> string(1) "1" 
      ["name"]=> string(89) "YES, I agree to be contacted by ... for promotions and special offers." 
      ["display_order"]=> string(1) "1" 
      ["subscribers"]=> NULL 
     } 
    } 
} 
} 

因此,它很容易理解,我需要使用:

  1. 組ID在這種情況下,4909
  2. 和團體名稱,在這種情況下是:「是的,我同意由聯絡...爲促銷和優惠。」

就是這樣。作品! 希望這可以幫助別人。

乾杯, 文斯。

+1

對我來說,我無法獲得分組ID,但它的工作原理是使用它的名字。 – Mike

相關問題