Php 在mailchimp api上添加组时遇到问题
我有一个ajax表单,可以将电子邮件地址正确地提交给mailchimp,但我不知道如何集成组 以下是我的submit.php代码:Php 在mailchimp api上添加组时遇到问题,php,jquery,ajax,mailchimp,Php,Jquery,Ajax,Mailchimp,我有一个ajax表单,可以将电子邮件地址正确地提交给mailchimp,但我不知道如何集成组 以下是我的submit.php代码: <?php header("HTTP/1.1 200 OK"); if ((isset($_POST['email'])) && (strlen(trim($_POST['email'])) > 0)) $email = trim(stripslashes(strip_tags($_POST['email']))); else $ema
<?php header("HTTP/1.1 200 OK");
if ((isset($_POST['email'])) && (strlen(trim($_POST['email'])) > 0))
$email = trim(stripslashes(strip_tags($_POST['email'])));
else
$email = '';
// download from http://apidocs.mailchimp.com/api/downloads/
require_once 'MCAPI.class.php';
$apikey = 'my-key';
$listId = 'my-list-id';
$apiUrl = 'http://api.mailchimp.com/2.0/';
// create a new api object
$api = new MCAPI($apikey);
// Interest Groups
$merge_vars = array(
'groupings' => array(
array(
'name' => "How often?",
'groups' => array("subscribe for weekly inspiration","subscribe for daily inspiration")
)
)
);
if($email !== '') {
$return_value = $api->listSubscribe( $listId, $email, $merge_vars );
// check for error code
if ($api->errorCode){
echo "<p>Error: $api->errorCode, $api->errorMessage</p>";
} else {
echo '<p>Well hello there!</p>';
}
}
?>
这是我的html ajax表单:
<div id="form-container">
<label for="email-address">Email address</label>
<input type="email" id="email-address" name="email-address" placeholder="Please enter your email." value="">
<div id="interestTable">
<div id="mergeRow-100-1" class="mergeRow dojoDndItem mergeRow-interests-checkboxes">
<label>How often?</label>
<div class="field-group groups">
<ul class="interestgroup_field checkbox-group">
<li class="below12"> <label class="checkbox" for="group_1"><input type="checkbox" id="group_1" name="group[1][1]" value="1" class="av-checkbox"><span>subscribe for weekly inspiration</span> </label> </li>
<li class="below12"> <label class="checkbox" for="group_2"><input type="checkbox" id="group_2" name="group[1][2]" value="1" class="av-checkbox"><span>subscribe for daily inspiration</span> </label> </li>
</ul>
</div>
</div>
</div>
<!-- for bots -->
<div style="position: absolute; left: -6000px;"><input type="text" id="extra-info" name="extra-info" tabindex="-1" value=""></div>
<button type="button" name="subscribe" id="subscribe">Submit</button>
</div>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script>
jQuery("#subscribe").click(function() {
var email = jQuery("#email-address").val();
var other_text = jQuery("#extra-info").val();
// don't send if we have other text
if(other_text === '') {
if(email !== '')
jQuery.ajax({
type: "POST",
async: true,
data: {
email: email
},
url: "submit.php",
dataType: "html",
success: function (data)
{ jQuery("#form-container").html(data); },
error: function (err)
{ alert(err.responseText);}
});
}
});
</script>
电子邮件地址
多久?
- 订阅每周灵感
- 订阅每日灵感
提交
jQuery(“#订阅”)。单击(函数(){
var email=jQuery(“#电子邮件地址”).val();
var other_text=jQuery(“#额外信息”).val();
//如果我们有其他文本,请不要发送
如果(其他_文本==''){
如果(电子邮件!='')
jQuery.ajax({
类型:“POST”,
async:true,
数据:{
电邮:电邮
},
url:“submit.php”,
数据类型:“html”,
成功:功能(数据)
{jQuery(“#表单容器”).html(数据);},
错误:函数(err)
{alert(err.responseText);}
});
}
});
有人知道我遗漏了什么,或者我可以在哪里找到答案吗?您使用“groupings”作为小写字符串,但显示的是全大写字符串。将其更改为“所有大写字母”将为您解决此问题。谢谢,皮特!我想我看到他们把它改成了小写。我在2.0中工作。你能更新问题以获得正确的代码吗?上面的代码似乎正在使用v1.3。api url已更改。抱歉搞混了!看起来您仍在使用v1.3。php使用的是v1.3,而不是v2.0。