Skip to content

Instantly share code, notes, and snippets.

@enamhasan
Last active July 13, 2022 15:30
Show Gist options
  • Save enamhasan/3f402b5b0e5e2065048f97e78498b796 to your computer and use it in GitHub Desktop.
Save enamhasan/3f402b5b0e5e2065048f97e78498b796 to your computer and use it in GitHub Desktop.
Mailchimp-Shopify-Ajax-submission
<div class="success" style="display: none;">{{ settings.success_message }}</div>
{%- if settings.newsletter_form_action != "" -%}
<form id="mc4wp-form-footer" name="nlr" class="mc4wp-form mc4wp-form-{{block.id}} mc4wp-form-basic" method="get" action="{{ settings.newsletter_form_action }}" target="_blank" data-id="{{block.id}}">
<div class="mc4wp-form-fields">
<p class="mailchimp-input-icon">
<label>Email address: </label>
<input type="email" name="EMAIL" placeholder="{{ 'general.newsletter_form.email_placeholder' | t }}" value="{%- if customer -%}{{ customer.email }}{%- endif -%}" required="">
</p>
<p>
<input type="submit" value="{{ 'general.newsletter_form.submit' | t }}">
</p>
{%- if bottom -%}<div class="hidden hide"></div>{%- endif -%}
</div>
</form>
{% endif %}
<script>
$("#mc4wp-form-footer").submit(function(e) {
e.preventDefault(); // avoid to execute the actual submit of the form.
var frm = $(this);
$.ajax({
type: frm.attr('method'),
url: frm.attr('action'),
data: frm.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) {
// $form.hide();
//alert("ft");
$('div.success').show();
//$('div.success').html('Sign up successful! Thank you.');//.delay(100000).fadeOut();
}
});
});
</script>
</script>
<!-- https://woodlifeprints.us10.list-manage.com/subscribe/post-json?u=486fb7f158a6eb6bca2cf442d&amp;id=44fc3b65e2&c=? -->
<!--http://xxxxx.us#.list-manage1.com/subscribe/post-json?u=xxxxx&id=xxxx&c=?" method="get" -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment