1

I've created a simple page and trying to add a MailChimp sign-up form using the script from https://github.com/drewm/mailchimp-api/blob/master/README.md.

I've added the below code in my index.php and it seems to be working perfectly.

<form id="signup" action="index.html" method="get">
    First Name: <input type="text" name="fname" id="fname" />
    Last Name: <input type="text" name="lname" id="lname" />
    email Address (required): <input type="email" name="email" id="email" />
    <input type="submit" id="SendButton" name="submit" value="Submit" />
</form>
<div id="message"></div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
    $('#signup').submit(function() {
        $("#message").html("Adding your email address...");
        $.ajax({
            url: 'mailchimp/src/store-address.php', // proper url to your "store-address.php" file
            type: 'POST', // <- IMPORTANT
            data: $('#signup').serialize() + '&ajax=true',
            success: function(msg) {
                var message = $.parseJSON(msg),
                    result = '';
                if (message.status === 'pending') { // success
                    result = 'Success!  Please click the confirmation link that will be emailed to you shortly.';
                } else { // error
                    result = 'Error: ' + message.detail;
                }
                $('#message').html(result); // display the message
            }
        });
        return false;
    });
});
</script>

However I would like to remove the first name and last name in the form. Simple removing the lines in the code wont work.

Think it has something to do with data: $('#signup').serialize() + '&ajax=true',. But im not sure. Can anyone point me in the right direction?

Thanks in advance!

Aart
  • 11
  • 2

0 Answers0