I saw on the Mailchimp website that you can redirect the user to a custom thank you page when they subscribe to your mailing list, but that's not exactly what I want to do.
When a user subscribe to my mailing list, I want to hide the form and replace it with a thank you note directly on my page without any redirection. Is there a way to do that?
You can do this by modifying the form action.
Change “subscribe/post” to “subscribe/post-json” …
<form action="...list-manage.com/subscribe/post-json?u=...."
Add a submit handler to the form:
$("#subscribe-form").submit(function(e){
e.preventDefault();
submitSubscribeForm($("#subscribe-form"));
});
Submit the form via AJAX (Code referenced from Github here):
function submitSubscribeForm($form, $resultElement) {
$.ajax({
type: "GET",
url: $form.attr("action"),
data: $form.serialize(),
cache: false,
dataType: "jsonp",
jsonp: "c",
contentType: "application/json; charset=utf-8",
error: function(error){},
success: function(data){
if (data.result != "success") {
var message = data.msg || "Sorry. Unable to subscribe. Please try again later.";
if (data.msg && data.msg.indexOf("already subscribed") >= 0) {
message = "You're already subscribed. Thank you.";
}
$resultElement.html(message);
} else {
And then write the code to display the signup confirmation
$resultElement.html("Thank you!<br>You must confirm the subscription in your inbox.");
}
}
});
}