Reputation: 309
Currently.. I have the mailchimp api all connected and working and when I click submit on my form it automatically registers my email.. However, there is a $my_email which is predefined and as well arrays under $merge_vars which are predefined as shown below...
$merge_vars = array('FNAME' => 'Test', 'LNAME'=>'Account',
);
$my_email = '[email protected]';
Now, I've been trying to pull the REAL FNAME and LNAME that will be entered in the mailing form which passes onto the subscribe form with their information, because otherwise.. no matter what.. The form technically isn't doing anything other than having the form action of the listSubscribe.php and submitting predefined information.
How can I pass this info along? I'm at the last step..
I thought it would be something along the lines of like the mailchimp name/id it pulls like how it does for the embedded form by doing a GET request for the name of the field.. But this doesn't work which I thought how it used to work and just shows up blank in mailchimp for the subscriber.
$merge_vars = Array(
'email' => $_GET['email'],
'FNAME' => $_GET['FNAME'],
'LNAME' => $_GET['LNAME'],
'MMERGE3' => $_GET['MMERGE3'],
'MMERGE3' => $_GET['MMERGE4']
);
To clarify, I'm trying to pull my mailchimp form's information via the API how I got it setup, any good way?
<?php
require_once 'inc/MCAPI.class.php';
require_once 'inc/config.inc.php'; //contains apikey
$api = new MCAPI($apikey);
$merge_vars = array('FNAME' => 'Test', 'LNAME'=>'Account',
);
// By default this sends a confirmation email - you will not see new members
// until the link contained in it is clicked!
$retval = $api->listSubscribe( $listId, $my_email, $merge_vars );
if ($api->errorCode){
echo "Unable to load listSubscribe()!\n";
echo "\tCode=".$api->errorCode."\n";
echo "\tMsg=".$api->errorMessage."\n";
} else {
echo "Subscribed - look for the confirmation email!\n";
}
?>
Snippet of my form..
<div class="email-form">
<div id="mc_embed_signup">
<form action="mcapi_listSubscribe.php" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
<div id="mc_embed_signup_scroll">
<hr>
<div class="mc-field-group">
<label for="mce-FNAME">First Name:</label>
<input type="text" value="" name="FNAME" class="" id="fn">
</div><hr>
<div class="mc-field-group">
<label for="mce-LNAME">Last Name:</label>
<input type="text" value="" name="LNAME" class="" id="ln">
</div><hr>
<div class="mc-field-group">
<label for="mce-EMAIL">Email: <span class="asterisk">*</span>
</label>
<input type="email" value="" name="EMAIL" class="required email" id="em">
</div><hr>
<label for="mce-MMERGE3">Telephone: </label>
<input type="text" name="MMERGE3" class="tel" value="" id="tp">
<label for="mce-MMERGE4">Zip Code: </label>
<input type="text" value="" name="MMERGE4" class="zip" id="z">
<hr>
<div class="mc-field-group input-group">
<input type="checkbox" value="1" name="group[17901][2]" id="real">
<label for="chk" class="chk">I am a homebuyer</label>
<br>
<input type="checkbox" value="1" name="group[17901][1]" id="real">
<label for="chk" class="chk">I am a realtor/broker</label>
</div>
<div style="position: absolute; left: -5000px;"><input type="text" name="b_2c388f1367d49e756e70a6ef2_6b9ad77da3" tabindex="-1" value=""></div>
<div class="clear"><input type="submit" value="REGISTER" name="subscribe" id="mc-embedded-subscribe" class="button"></div>
</div>
</form>
<div id="mce-responses" class="clear">
<div class="response" id="mce-error-response" style="display:none"></div>
<div class="response" id="mce-success-response" style="display:none"></div>
</div> <!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups-->
</div>
</div>
<!--End mc_embed_signup-->
</div>
Upvotes: 0
Views: 499
Reputation: 309
I was using POST method with GET request for the name fields. My mistake was that I had to do a POST request considering my form is using a POST method not GET.
<form action="mcapi_listSubscribe.php" method="post"
It should look like..
$merge_vars = Array(
'email' => $_POST['email'],
'FNAME' => $_POST['FNAME'],
not...
$merge_vars = Array(
'email' => $_GET['email'],
'FNAME' => $_GET['FNAME'],
Upvotes: 0