Last active
May 8, 2021 09:26
-
-
Save ry8806/8c54c7ad455443dc4589f3f4991d0979 to your computer and use it in GitHub Desktop.
Elastic Email + JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form id="subscribeForm"> | |
<input id="email-input" type="text" /> | |
<button type="submit">Submit</button> | |
</form> |
you could do something like:
var myAccountId = "this-is-my-account-id"
and then:
// DOM Ready, call the function defined above with parameters
jQuery(function () {
SetupNewsletterSubscribe(myAccountId, "NameOfEmailList", "subscribeForm", function () {
// Do stuff here when the email address has been added to the service!
});
});
this actually does not send any email (obviously i've replaced the id with my public id, any help on this? maybe a javascript version instead of jquery?
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-id", "Flarumsub", "subscribeForm", function () {
});
});
Correct, this doesn't send emails and it's not meant to.
This simply adds the given email address to your list of contacts in Elastic Email, under the specified list (from listName
)
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();
$('#email-input').val('');
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how can i use a variable here:
SetupNewsletterSubscribe("my variable*"