Skip to content

Instantly share code, notes, and snippets.

@ry8806
Last active May 8, 2021 09:26
Show Gist options
  • Select an option

  • Save ry8806/8c54c7ad455443dc4589f3f4991d0979 to your computer and use it in GitHub Desktop.

Select an option

Save ry8806/8c54c7ad455443dc4589f3f4991d0979 to your computer and use it in GitHub Desktop.
Elastic Email + JavaScript
<form id="subscribeForm">
<input id="email-input" type="text" />
<button type="submit">Submit</button>
</form>
function SetupNewsletterSubscribe(publicAccountId, listName, formId, onSuccess) {
var eeUrl = "https://api.elasticemail.com/v2/contact/add";
var email = jQuery("#email-input");
var form = jQuery("#" + formId).submit(function (event) {
event.preventDefault();
jQuery.post(eeUrl, {
email: email.val(),
publicAccountId: publicAccountId,
listName: listName
}, function () { }, "json").done(function (result) {
if (result.success == true) {
onSuccess();
}
}).fail(function () {
// Do something here if it fails...
});
});
};
// DOM Ready, call the function defined above with parameters
jQuery(function () {
SetupNewsletterSubscribe("**MY_PUBLIC_ACCOUNT_ID**", "NameOfEmailList", "subscribeForm", function () {
// Do stuff here when the email address has been added to the service!
});
});
@justoverclockl
Copy link
Copy Markdown

justoverclockl commented May 8, 2021

oh that's the reason, anyway it works fine, just the last question, how to clear field after submission?
now i'm using
document.getElementById("subscribeForm").reset();

@ry8806
Copy link
Copy Markdown
Author

ry8806 commented May 8, 2021

$('#email-input').val('');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment