我被困在如何使用API 2.0检索和发送我的复选框的值在Mailchimp表单中。 在表单的最后,我有这个复选框
<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
所有字段都会发送凭证,日期,销售,姓名和电话,并在我的列表中订阅用户。我缺少的唯一值是复选框。我想发送至少&#34;是&#34;或&#34; 1&#34;到我的复选框列表。 想不通!
有什么建议吗?
感谢。 文斯。
答案 0 :(得分:1)
确定1小时后发布我的问题我找到了解决方案。
这里有适合我的正确代码:
$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
}
}
}
}
因此我很容易理解我需要使用:
就是这样。作品! 希望这有助于其他人。
干杯, 文斯。