2个签名表单(相同)在同一页面上(使用Mailchimp PHP API)

时间:2015-04-02 11:52:16

标签: php forms mailchimp

各位大家好,感谢您抽出宝贵时间阅读本文。 情况如下:

  

我在同一页面上使用了同一个注册表单。

     

我正在为这些表单使用PHP Mailchimp API。

     

问题:当只使用一个表单并注释掉另一个表单时,提交到Mailchimp列表的工作正常,但是当两个表单都处于活动状态时,只有第二个表单有效。

如果两种表单都有效,我该怎么办?

感觉必须有一个关于如何处理这个的PHP规则,因为我正在学习,我不知道这一点。如果对于更有经验的用户来说这是显而易见的,请道歉。

我附上了下面的代码(没有样式和页面内容)。出于安全原因,我还通过XXXXXXX切换了API密钥。

再次感谢您的时间!

<?php
$config = array(
'apiKey' => 'XXXXXXX',
'listId' => '781e67f6db',
'email'  => $_POST['email'],
);
$errorCodes = array(
230 => 'You already subscribed to this mailing list. Thanks!',
232 => 'This isn\'t valid e-mail address.',
);
$api = new MCAPI($config['apiKey']);

$merge_vars = array('FNAME'=> $_POST['FNAME'], 'LNAME'=> $_POST['LNAME'],         array(
'GROUPINGS' =>        array(
        'name' => "Tribeca Studios Homepage (idle1)", // You can use either 'name' or 'id' to identify the group
        'groups' => array("Tribeca Studios Homepage (idle1)","Tribeca Studios Homepage (idle1)")
  ))
);

$double_optin = false; 
$send_welcome = false;

?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>


<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p class="center_it">
<input name="FNAME" placeholder="First Name" type="text" class="input-sm"/>
<input name="LNAME" placeholder="Last Name" type="text" class="input-sm"/>
<input type="email" name="email" placeholder="Email" class="input-sm" >


<p class="text-center">
<input type="submit" class="btn btn-yellow" value="Continue">
</p></p>

<p class="text-center errormsg">
<?php if (filter_var($config['email'], FILTER_VALIDATE_EMAIL)): ?>
<?php if ($api->listSubscribe($config['listId'], $config['email'],$merge_vars,$double_optin,$send_welcome)): ?>
<p style="background:lightgreen">Success</p>
<?php else: ?>
<p style="border:solid red;max-width:600px;">There was a problem with your submission. Please try again. If the issue persists, contact us at <a href="mailto:hello@tribecastudios.co.uk">hello@tribecastudios.co.uk</a> (Error code: <?php echo $api->errorCode; ?>)</p>
<?php endif; ?>
<?php else: ?>
</p>
</form>
<?php endif; ?>

<p></p>


<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p class="center_it">
<input name="FNAME" placeholder="First Name" type="text" class="input-sm"/>
<input name="LNAME" placeholder="Last Name" type="text" class="input-sm"/>
<input type="email" name="email" placeholder="Email" class="input-sm" >


<p class="text-center">
<input type="submit" class="btn btn-yellow" value="Continue2">
</p></p>

 <p class="text-center errormsg">
 <?php if (filter_var($config['email'], FILTER_VALIDATE_EMAIL)): ?>
 <?php if ($api->listSubscribe($config['listId'], $config['email'],$merge_vars,$double_optin,$send_welcome)): ?>
 <p style="background:lightgreen">Success</p>
 <?php else: ?>
 <p style="border:solid red;max-width:600px;">There was a problem with your    submission. Please try again. If the issue persists, contact us at <a href="mailto:hello@tribecastudios.co.uk">hello@tribecastudios.co.uk</a> (Error code: <?php echo $api->errorCode; ?>)</p>
<?php endif; ?>
<?php else: ?>
      </p>

</form>
<?php endif; ?>
</body>
</html>

0 个答案:

没有答案