I'm building off this sample file and trying to add a first name field. The email form connects with my list, so I know its communicating with the Mailchimp servers fine. It's sending the email, but the first name field wont connect properly and I cant figure out why. It's as if 'FNAME' isn't the right name in the DB, but that's what it's called in my list view. What am I missing? Thanks
My form
<form id="signup" action="<?=$_SERVER['PHP_SELF']; ?>" method="get">
<fieldset>
<span id="response">
<? require_once('inc/store-address.php'); if($_GET['submit']){ echo storeAddress(); } ?>
</span>
<div class="formColumn">
<label for="fname" id="fname">First Name</label>
<input type="text" name="fname" id="fname">
</div>
<div class="formColumn">
<label for="email" id="address-label">Email Address</label>
<input type="text" name="email" id="email" />
</div>
<input type="image" src="img/submit.png" name="submit" value="Join" class="btn" alt="Join" />
</fieldset>
</form>
Store-address.php
<?php
function storeAddress(){
// Validation
if(!$_GET['email']){ return "No email address provided"; }
$merge_vars = array(
'EMAIL' => $_GET['email'],
'FNAME' => $_GET['fname']
);
if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$/i", $_GET['email'])) {
return "Email address is invalid";
}
require_once('MCAPI.class.php');
$api = new MCAPI('hiding my ID');
// Click the "settings" link for the list - the Unique Id is at the bottom of that page.
$list_id = "hiding my list id";
if($api->listSubscribe($list_id, $_GET['email'], $merge_vars) === true) {
// It worked!
return 'Success! Check your email to confirm sign up.';
}else{
// An error ocurred, return error message
return 'Error: ' . $api->errorMessage;
}
}
// If being called via ajax, autorun the function
if($_GET['ajax']){ echo storeAddress(); }
?>
mailing-list.js
$(document).ready(function() {
$('#signup').submit(function() {
// update user interface
$('#response').html('Adding email address...');
// Prepare query string and send AJAX request
$.ajax({
url: 'inc/store-address.php',
data: 'ajax=true&email=' + escape($('#email').val()) + '&fname=' + escape($('#fname').val()),
success: function(msg) {
$('#response').html(msg);
}
});
return false;
});
});