Live DemoDownload Source Code

Getting Started

First we need to access the MailChimp dashboard to gather their HTML code. Sign into your account or create a new free account. Click “Lists” from the main menu and you’ll get a table of all your subscription lists. You might want to use an existing list, or create a new list for this tutorial. Either way click on the list’s name and we get another table organizing all the subscribers by e-mail address.
Any new list will start out empty but it doesn’t matter how many subscribers you have. On this page click “Signup forms” and we’ll be presented with some options. General forms are too basic and we don’t have control over the code. Select “embedded forms” and you’ll get a sleek interface to copy/paste the HTML.
mailchimp dashboard preview screenshot embedded code
I’ve chosen Super Slim over Classic because there’s less CSS getting in the way of your design, yet it’s still better than Naked without any styles at all.


The block above is my default code from MailChimp. There is a lot of organizing to do, namely removing all the comments unless you really need them. Also I’ve created a new stylesheet styles.css and I’m going to combine everything together. The inline #mc_embed_signup should be merged into a unified CSS file along with the MailChimp slim code. This is my strategy for customizing the original design and sprucing up the layout altogether.

Changes in HTML

It’ll be easier to explain this process by showing the updated block of code so you have the ability to compare. All of the classes and IDs and names have been left alone. It’s wiser to customize the CSS by using the existing classes/IDs to ensure compatibility.


The most important change is my form’s action attribute. Everything in the URL is identical up until post-json, which was originally post in the MC template. The post action returns a typical completion page we’re all familiar with. post-json will return a JSON response based on the success or failure of the e-mail subscription. Please note I’ve also appended &c=? to the end of this URL.
The purpose would be to delegate a callback method which is synonymous in JSON responses. I haven’t found a use for it personally, but there are many posts and discussion threads on the topic of callback functions. Just remember it should be part of the action URL.
Also you might notice an extra div at the very bottom of the form container. I’m using the ID #notification_container in a familiar syntax like the MailChimp ID names. Once JSON returns a value we check in JavaScript and then it’s appended onto the page inside this div.

Updating CSS

Aside from the typical page resets I’ve also written my own styles for the alert/success message containers. The properties are fairly typical so I won’t go into details, but you can find them inside my consolidated styles.css file.
The best way to customize MC form styles is to recognize how you want it to look. The form is a mixed bag of percentages and pixels, so it’s really up to you as the designer to make what you want. Responsive or fixed, inline or block-style elements. etc.
I’ve added some extra spacing to my code so there are block-level selectors and inline styles.


This is just a small portion and it focuses on the inputs and the submit button. I’m using a bottom border to make the button appear 3D which then flattens when clicked. It’s all pretty straightforward and none of my CSS code should be confusing. I just repositioned the form container at 350px width so everything appears centered on the page.
Your positioning will change if you need it within the sidebar, or the header or maybe even the footer. In these cases you might relocate the notifications container above the form, or whatever makes the most sense. Feel free to start off with my code but starting with MailChimp’s defaults are probably just as good.


If we used the original action URL we could stop at this point and be done. The form is mostly redesigned and once a user clicks submit, a new tab would open asking them to confirm the subscription via e-mail. But to simplify this process we’ll look into a jQuery alternative for handling the submission.

MailChimp Signup and jQuery

If you don’t already have a copy of jQuery then download one and include it within the page header. All my code is written in script tags at the bottom of the page. I actually stumbled onto this solution in Stack Overflow which outlined much of the process.


Right when the document is loaded I’m setting up a jQuery reference variable $form. Whenever the submit button is clicked we prevent the default submission(which would open a JSON results page) and instead call a user-defined function named register(). The $form itself is passed into the function as a parameter.


It might appear confusing but this function is really one long .ajax() method. Notice we can pull the GET/POST attribute off the form itself, along with the updated action URL. All the input values are serialized and passed in just like PHP. This is the primary reason to leave form input names alone and keep the original template.
Finally there are two Ajax response callbacks on success or error. If we get an error then MailChimp could not accept our request and the alert message appears. Otherwise they did accept the request, but we don’t know if it worked.
If Ajax was successful then we get a new parameter which is returned into jQuery. In this case it’s named data which should appear like a JSON object. If the result data says it didn’t work then we know there’s a problem with the e-mail address, either not valid or just not an e-mail string. Either way the error message is output into the page. I’m using substr() to remove the first portion of the error message code.
Or if the data message is successful, we should get a return string stating the user needs to check their inbox and confirm this new subscription. Either way the return message is output into the notification container by using jQuery’s .html() method.
Please note that even if you signup with a random e-mail, this will not appear in your list until it has been confirmed. To check if this script actually works you’ll need to use a real address and click the confirmation e-mail.
Live DemoDownload Source Code

Closing

I’ve always been slightly annoyed by the MailChimp default opt-in form. I hope this tutorial can offer a slightly different approach to web developers and Internet marketers. Also remember that you can update the interface design for confirmation pages and emails sent out to each subscriber. Feel free to download my source code and include this updated MailChimp form within any of your own projects.