Skip to content

Instantly share code, notes, and snippets.

@joeswann
Last active June 14, 2018 00:49
Show Gist options
  • Save joeswann/a24ce711d8565a90ca65 to your computer and use it in GitHub Desktop.
Save joeswann/a24ce711d8565a90ca65 to your computer and use it in GitHub Desktop.

Revisions

  1. Joe Swann revised this gist Jun 14, 2018. No changes.
  2. Joe Swann revised this gist Jun 19, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion mailchimp.html
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    <form class="newsletter" action="https://companyofstrangers.us2.list-manage.com/subscribe/post-json?u=xxxxxxx&id=xxxxxxxx&c=?" method="get" >
    <form class="newsletter" action="https://example.us2.list-manage.com/subscribe/post-json?u=xxxxxxx&id=xxxxxxxx&c=?" method="get" >
    <div class="close"></div>
    <div class="success">
    Thankyou for signing up!
  3. Joe Swann revised this gist Mar 9, 2015. 2 changed files with 16 additions and 4 deletions.
    12 changes: 12 additions & 0 deletions mailchimp.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    <form class="newsletter" action="https://companyofstrangers.us2.list-manage.com/subscribe/post-json?u=xxxxxxx&id=xxxxxxxx&c=?" method="get" >
    <div class="close"></div>
    <div class="success">
    Thankyou for signing up!
    </div>
    <div class="error">
    Please check your email address is correct.
    </div>
    <input name="NAME" type="text" placeholder="Full Name" />
    <input name="EMAIL" type="text" placeholder="Email Address" />
    <button class="btn-alt" type="submit" value="Sign Up" name="submit">Sign Up</button>
    </form>
    8 changes: 4 additions & 4 deletions mailchimp.js
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,9 @@
    //handler for CM form
    //handler for Mailchimp form
    handlerNewsletter: function() {
    var $form_wrap = $('.newsletter-wrap');
    var $form = $form_wrap.find('.newsletter');
    var $success = $form.find('.success');
    var $error = $form.find('.error');
    var $form = $form_wrap.find('.newsletter');
    var $success = $form.find('.success');
    var $error = $form.find('.error');

    var action = String($form.attr('action'));

  4. Joe Swann revised this gist Nov 2, 2014. 1 changed file with 24 additions and 13 deletions.
    37 changes: 24 additions & 13 deletions mailchimp.js
    Original file line number Diff line number Diff line change
    @@ -1,25 +1,36 @@
    //Handler for Mailchimp form
    handlerNewsletterSubmit: function() {
    var $form = $('footer .newsletter form');
    //handler for CM form
    handlerNewsletter: function() {
    var $form_wrap = $('.newsletter-wrap');
    var $form = $form_wrap.find('.newsletter');
    var $success = $form.find('.success');
    var $error = $form.find('.error');

    var action = String($form.attr('action'));

    $form.submit(function(e) {
    e.preventDefault();

    $error.hide();
    $.getJSON(this.action + "?callback=?",
    $(this).serialize(),
    function(data) {
    if (data.Status === 400) {
    $error.text(data.Message).show();
    } else { // 200
    $.ajax({
    type: $form.attr('method'),
    url: action,
    data: $form.serialize(),
    cache: false,
    dataType: 'json',
    contentType: "application/json; charset=utf-8",
    error: function(err) {
    alert("Could not connect to the registration server. Please try again later.");
    },
    success: function(data) {
    if (data.result != "success") {
    // Something went wrong, do something to notify the user. maybe alert(data.msg);
    $error.text('Please enter a valid email address').show();
    } else {
    // It worked, carry on...
    $form.find('input').val('');
    $success.show();
    js.utilRemoveLightbox();
    }
    }
    ); // end getJson

    });
    }); // end submit
    },
    }
  5. Joe Swann created this gist Nov 2, 2014.
    25 changes: 25 additions & 0 deletions mailchimp.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    //Handler for Mailchimp form
    handlerNewsletterSubmit: function() {
    var $form = $('footer .newsletter form');
    var $success = $form.find('.success');
    var $error = $form.find('.error');

    $form.submit(function(e) {
    e.preventDefault();

    $error.hide();
    $.getJSON(this.action + "?callback=?",
    $(this).serialize(),
    function(data) {
    if (data.Status === 400) {
    $error.text(data.Message).show();
    } else { // 200
    $form.find('input').val('');
    $success.show();
    js.utilRemoveLightbox();
    }
    }
    ); // end getJson

    }); // end submit
    },