0

I'm relatively new to mailchimp and have been using this post to implement a very simple email capture form that will redirect to a new landing page on submit. I have been using this post: using an existing form to send data to mailchimp, then redirect

I understand everything in the post except I need an example for this statement:

"However, if you want to redirect, you'd simply alter your jQuery ajax function to do so."

Can someone provide an example of how to alter the jQuery ajax function? Also I don't need it to return a success or failure message, I just need it to capture the name / email and then immediately redirect to the next page.

Thanks

Community
  • 1
  • 1

1 Answers1

0

Sparky is saying that you can modify the success function of the AJAX that is part of the submit function tied to form $('#signup').

i.e., Currently the success function is:

...
success: function(msg) {
        $('#message').html(msg);
    }
...

And you could just update to redirect doing something like:

...
success: function(msg) {
        document.location = '/target/path/file.html';
    }
...

EDIT - Doing the above will redirect the browser - so long as the AJAX call is successful (not necessarily that the API call was successful.) So even if the PHP is returning an error in the message - the success function is called because it is referring to the success of the AJAX call itself.

If you want to redirect only on a successful message returned by the PHP file then you'll have to check the incoming msg and handle accordingly.

...
success: function(msg) {
  if (msg.indexOf('Success') != -1) {
   document.location = '/target/path/file.html';
  } else {
   $('#message').html(msg);
  }
}
...

This will redirect the browser on a successful message return from the PHP file, otherwise it will display the message in $('#message') .

Joel
  • 1,650
  • 2
  • 13
  • 20
  • Joel thanks for the quick reply. Is there anything I need to alter in the store-address.php file as well? Right now that php is set up to validate the email, and display either an error to the user or a success message. I don't really need to display any message, just need to post the email into my mailchimp list, and redirect them to the next page. I think when I updated the ajax it must be in conflict with the PHP because it's no longer storing the address. – user2832002 Sep 30 '13 at 20:04
  • Gotcha... see my edit in the answer. success in AJAX just means that the AJAX call was successful - the message contained therein very well contain an error string. – Joel Oct 01 '13 at 13:19