jeudi 2 avril 2015

2 sign forms (identical) on the same page (using Mailchimp PHP API)

Hello everyone and thank you for taking the time to read this. Here is the situation:



I am using 2 of the same sign up form on the same page.


I am using the PHP Mailchimp API for these forms.


Issue: When using only one form and commenting out the other, submission to the Mailchimp list works fine though when both forms are active, only the second one works.



What can I do to have both forms work?


It feels like there must be a php rule on how to handle this and because I am learning as I go, I don't know this. Apologies if this is obvious for more experienced users.


I attached the code below (without styling and page content). I also switched the API key by XXXXXXX for security reasons.


Thank you again for your time!



<?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>

Aucun commentaire:

Enregistrer un commentaire