Last active
August 29, 2015 14:15
-
-
Save vishalbasnet23/92c3007bf5ff259aeb08 to your computer and use it in GitHub Desktop.
Mail chimp 1.3 PHP API on ajax call
This file contains hidden or 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
| <?php | |
| require get_template_directory() . '/inc/mailchipapi.php'; | |
| add_action('wp_ajax_add_to_mailchimp_list', 'add_to_mailchimp_list', 0); | |
| add_action('wp_ajax_nopriv_add_to_mailchimp_list', 'add_to_mailchimp_list'); | |
| function add_to_mailchimp_list() { | |
| $apiKey = 'YOUR_API_KEY'; | |
| $listId = 'YOUR_LIST_ID'; // End Customer | |
| $double_optin=false; | |
| $send_welcome=false; | |
| $email_type = 'html'; | |
| $email = $_POST['email']; | |
| $api = new MCAPI($apiKey); | |
| $retval = $api->listSubscribe( $listId, $email,"", "", "false"); | |
| if ($api->errorCode){ | |
| echo $api->errorMessage; | |
| } else { | |
| echo "Thank you for Subscription, you are added to our list!"; | |
| } | |
| die(); | |
| } | |
| ?> |
This file contains hidden or 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
| <div class="col-sm-6 col-sm-6-2"> | |
| <form class="form-inline" role="form" id="mailchimp" name="subscribe-form" method="POST"> | |
| <div class="form-group"> | |
| <input id="fname" type="text" name="name" placeholder="Name" value=""> | |
| <input id="email" type="email" name="email" placeholder="Email Address" value=""> | |
| <span id="ajax-overlay" > | |
| <input type="submit" value="Sign Up +" type="submit" class="btn" id="subscription-submit"> | |
| <span class="ajax-loader" style="display:none;"></span> | |
| </span> | |
| </div> | |
| <!-- <div class="subscription-loader"><</div> --> | |
| </form> | |
| <p class="notice"></p> | |
| </div><!--col-sm-6 ends--> | |
| <script> | |
| $('form#mailchimp').submit(function(e) { | |
| e.preventDefault(); | |
| $('.ajax-loader').show(); | |
| $('#ajax-overlay').addClass('submitted'); | |
| $(this).ajaxSubmit({ | |
| // jQuery('#subscription-submit').attr('disabled'); | |
| success : function (responseText) { | |
| $('.ajax-loader').hide(); | |
| $('#ajax-overlay').removeClass('submitted'); | |
| $('p.notice').text(responseText).fadeIn('slow'); | |
| if( responseText === 'Thank you for Subscription, you are added to our list!' ) { | |
| // | |
| } | |
| $('#fname').val(''); | |
| $('#email').val(''); | |
| }, | |
| url : ajaxVars.ajaxurl, | |
| data : { ajax_nonce : ajaxVars.ajax_nonce, action : 'add_to_mailchimp_list' }, | |
| type : 'POST', | |
| timeout : 50000, | |
| }); | |
| }); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment