GithubHelp home page GithubHelp logo

angular-mailchimp's Introduction

Installation

Install with bower:

bower install angular-mailchimp

Add a <script> to your index.html:

<script src="/bower_components/angular-mailchimp/angular-mailchimp.js"></script>

And add mailchimp as a dependency for your app:

angular.module('myApp', ['mailchimp']);

Justification of Method

Instead of relying on a resource or a service, I chose to make this module as reusable as possible. This means that all configuration is done in the HTML shown below. So, you can have one page with as many subscription forms as you'd like as long as you configure everything properly.

Configuration

  1. Log into your Mailchimp Account
  2. Click on "Lists" from the sidebar
  3. Click on the list for which you want
  4. Click "Signup forms"
  5. Select "Embedded forms"
  6. Select "Naked"

You must obtain the following information from the form action attribute code:

  • mailchimp.username - Your MailChimp username, immediately follows http://
  • mailchimp.dc - Your MailChimp distribution center, immediately follows your username
  • mailchimp.u - Unique string that identifies your account. It is obtained from
  • mailchimp.id - A unique string that identifies your list.

Example::

<form action="http://username.us1.list-manage.com/subscribe/post?u=a1b2c3d4e5f6g7h8i9j0&amp;id=aabb12" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>

Result:

  • mailchimp.username - username
  • mailchimp.dc - us1
  • mailchimp.u - a1b2c3d4e5f6g7h8i9j0
  • mailchimp.id - aabb12

Usage

The results from the last step will be populated in your form via ng-init.

So, add a <form> to your template as follows and replace the values with those you obtained:

<form name="MailchimpSubscriptionForm" ng-controller="MailchimpSubscriptionCtrl">
  <div ng-hide="mailchimp.result === 'success'">
    <input class="hidden" type="hidden" ng-model="mailchimp.username" ng-init="mailchimp.username='username'">
    <input class="hidden" type="hidden" ng-model="mailchimp.dc" ng-init="mailchimp.dc='us1'">
    <input class="hidden" type="hidden" ng-model="mailchimp.u" ng-init="mailchimp.u='a1b2c3d4e5f6g7h8i9j0'">
    <input class="hidden" type="hidden" ng-model="mailchimp.id" ng-init="mailchimp.id='aabb12'">
    <input type="text" name="fname" ng-model="mailchimp.FNAME" placeholder="First name">
    <input type="text" name="lname" ng-model="mailchimp.LNAME" placeholder="Last name">
    <input type="email" name="email" ng-model="mailchimp.EMAIL" placeholder="Email address" required>
    <button ng-disabled="MailchimpSubscriptionForm.$invalid" ng-click="addSubscription(mailchimp)">Join</button>
  </div>

  <!-- Show error message if MailChimp unsuccessfully added the email to the list. -->
  <div ng-show="mailchimp.result === 'error'" ng-cloak>
    <span ng-bind-html="mailchimp.errorMessage"></span>
  </div>

  <!-- Show success message if MailChimp returned successfully. -->
  <div ng-show="mailchimp.result === 'success'" ng-cloak>
    <span ng-bind-html="mailchimp.successMessage"></span>
  </div>
</form>

Custom Fields

You also have the option to include extra fields in your subscription form. For example, you can pass a phone number to MailChimp by providing a value for mailchimp.phone.

License

The MIT License

Copyright (c) 2014 Keith Hall

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.