Is there a way to avoid redirecting people to the thank you page with Mailchimp?

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 really what I want to do.

When a user subscribes to my mailing list, I want to hide the form and replace it with a thank you note right on my page without any redirection. Is there a way to do this?

0


source to share


1 answer


You can do this by changing the action of the form.

Change "subscribe / submit" to "subscribe / submit-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 provided here from Github ):

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 registration confirmation

                    $resultElement.html("Thank you!<br>You must confirm the subscription in your inbox.");
                }
            }
        });
    }

      

+6


source







All Articles