Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mailchimp-submitter

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mailchimp-submitter

Easily itegrate your forms with Mailchimp

  • 0.2.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Mailchimp Submitter

Easily integrate your HTML forms with Mailchimp JSONP Ajax.

Installing

yarn add mailchimp-submitter
# or
npm install mailchimp-submitter

Basic Usage

  1. Create your HTML form

    <!-- Ensure you add data-mc to your form to mailchimp-submitter will find it -->
    <form data-mc="true" id="my-form">
      <!-- Add required fields including: 'project', 'datacenter', 'u', 'id' -->
      <input type="hidden" name="project" value="MY-PROJECT-NAME" />
      <input type="hidden" name="datacenter" value="us7" />
      <input type="hidden" name="u" value="XXXXXXXXXXXXXXXXXXXXXXXXX" />
      <input type="hidden" name="id" value="XXXXXXXXXX" />
    
      <!-- Add mailchimp fields -->
      <input type="email" name="EMAIL" />
      <input type="text" name="FNAME" />
      <input type="text" name="LNAME" />
    
      <button>Subscribe</button>
    </form>
    
  2. Import functions in your JavaScript and initialize Mailchimp Submitter

    import MailchimpSubmitter from 'mailchimp-submitter'
    
    // Initialize mailchimp submitter on your forms with data-mc="true"
    MailchimpSubmitter()
    

Advanced Usage

Using callbacks as arguments

MailchimpSubmitter({
  // Optional callback before submitting form to Mailchimp.
  // Return false in this callback to cancel the form request (IE. validation).
  beforeSubmit: _formEl => {
    const isValid = validateForm()
    return isValid
  },

  // Optional callback after Mailchimp response
  callback: (_formEl, resp) => {
    if (resp.result === 'success') {
      alert('Successfully subscribed')
    } else {
      alert('Error: ' + resp.msg)
    }
  },
})

Using callbacks as event listeners

const myForm = document.getElementById('my-form')

myForm.addEventListener('mcBeforeSubmit', () => {
  console.log('Submitting form...')
})

myForm.addEventListener('mcCallback', ({ detail: resp }) => {
  if (resp.result === 'success') {
    alert('Successfully subscribed')
  } else {
    alert('Error: ' + resp.msg)
  }
})

FAQs

Package last updated on 08 Jul 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc