<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>ajax Archives - Michael Sunarlim</title>
	<atom:link href="https://sunarlim.com/tag/ajax/feed/" rel="self" type="application/rss+xml" />
	<link>https://sunarlim.com/tag/ajax/</link>
	<description>Random blurbs about web development, e-commerce and technology</description>
	<lastBuildDate>Fri, 19 Mar 2021 20:03:49 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.4.5</generator>

<image>
	<url>https://i0.wp.com/sunarlim.com/wp-content/uploads/2016/07/cropped-MS_Square_512x512.png?fit=32%2C32&#038;ssl=1</url>
	<title>ajax Archives - Michael Sunarlim</title>
	<link>https://sunarlim.com/tag/ajax/</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">30613895</site>	<item>
		<title>MailChimp Subscribe Form with PHP, jQuery and AJAX (API 3.0)</title>
		<link>https://sunarlim.com/2017/01/mailchimp-subscribe-form-php-jquery-api3/</link>
					<comments>https://sunarlim.com/2017/01/mailchimp-subscribe-form-php-jquery-api3/#comments</comments>
		
		<dc:creator><![CDATA[Michael]]></dc:creator>
		<pubDate>Mon, 09 Jan 2017 06:48:18 +0000</pubDate>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[mailchimp]]></category>
		<category><![CDATA[php]]></category>
		<guid isPermaLink="false">https://sunarlim.com/?p=2591</guid>

					<description><![CDATA[<p>By popular demand, I updated my code and posted it as new GitHub repository that utilizes newer MailChimp API 3.0. Please read the tutorial below to create AJAX based MailChimp subscribe form on your PHP website with a little jQuery knowledge. Original post using (older and no longer supported) MailChimp API 1.0 can be found here. What... <span class="more"><a class="more-link" href="https://sunarlim.com/2017/01/mailchimp-subscribe-form-php-jquery-api3/">Continue reading <span class="meta-nav">&#8594;</span></a></span></p>
<p>The post <a href="https://sunarlim.com/2017/01/mailchimp-subscribe-form-php-jquery-api3/">MailChimp Subscribe Form with PHP, jQuery and AJAX (API 3.0)</a> appeared first on <a href="https://sunarlim.com">Michael Sunarlim</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>By popular demand, I updated my code and posted it as <a href="https://github.com/sunarlim/mailchimp-subscribe-api-v3" target="_blank" rel="noopener">new GitHub repository</a> that utilizes newer MailChimp API 3.0. Please read the tutorial below to create AJAX based MailChimp subscribe form on your PHP website with a little jQuery knowledge.</p>
<p>Original post using (older and no longer supported) MailChimp API 1.0 can be found <a href="https://sunarlim.com/2014/04/mailchimp-sign-form-php-jquery-ajax/">here</a>.</p>
<h3>What this code does</h3>
<ul>
<li>Validate field contents</li>
<li>Pass the form submission to MailChimp and add the record to your list</li>
<li>Basic fallback method for very, very old browser or does not have JavaScript activated</li>
<li>Very customizable and easily expandable, depending on your requirements</li>
<li>jQuery and jQuery Validation plugin called from CDNJS to keep number of files to maintain at minimal</li>
</ul>
<p><span id="more-2591"></span></p>
<h3>Tools/Credits</h3>
<ol>
<li><a title="jQuery" href="http://jquery.com/" target="_blank" rel="noopener">jQuery</a></li>
<li><a title="jQuery Validation" href="http://jqueryvalidation.org/" target="_blank" rel="noopener">jQuery Validation Plugin</a></li>
<li><a title="MailChimp API Wrappers" href="https://github.com/drewm/mailchimp-api" target="_blank" rel="noopener">MailChimp API v3 PHP Wrapper</a></li>
</ol>
<h3>MailChimp API Key and List ID</h3>
<p>Below we start, we need to generate public API key from your MailChimp account and also identify your list ID. If you are not sure how to retrieve those, follow these links from MailChimp Knowledge Base to <a title="MailChimp - Finding or generating your API key" href="http://kb.mailchimp.com/accounts/management/about-api-keys#Finding-or-generating-your-API-key" target="_blank" rel="noopener">retrieve your account&#8217;s API key</a> and <a title="MailChimp - Find Your List ID" href="http://kb.mailchimp.com/lists/managing-subscribers/find-your-list-id" target="_blank" rel="noopener">find your list ID</a>.</p>
<h4>The Form Page (index.php)</h4>
<p>jQuery will handle the AJAX using <span class="lang:js decode:true crayon-inline">$.post</span>  method and jQuery Validation plugin will validate the field values including email address format.</p>
<p>For this example, I am including first name and last name as part of the form fields. Feel free to make adjustments as required. Although keep in mind after changing the form fields, you may also need to adjust the <span class="lang:default decode:true crayon-inline">subscribe.php</span>  file too.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="html" data-enlighter-linenumbers="false">&lt;html&gt;
&lt;head&gt;
  &lt;title&gt;MailChimp (API v3) Sign-Up Form&lt;/title&gt;
  &lt;script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.16.0/jquery.validate.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
    $(document).ready(function() {
      // jQuery Validation
      $("#signup").validate({
        // if valid, post data via AJAX
        submitHandler: function(form) {
          $.post("subscribe.php", { fname: $("#fname").val(), lname: $("#lname").val(), email: $("#email").val() }, function(data) {
            $('#response').html(data);
          });
        },
        // all fields are required
        rules: {
          fname: {
            required: true
          },
          lname: {
            required: true
          },
          email: {
            required: true,
            email: true
          }
        }
      });
    });
  &lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
  &lt;div id="wrapper"&gt;
    &lt;form id="signup" class="formee" action="subscribe.php" method="post"&gt;
      &lt;fieldset&gt;
        &lt;legend&gt;Sign Up&lt;/legend&gt;
        &lt;div&gt;
          &lt;label for="fname"&gt;First Name *&lt;/label&gt; &lt;input name="fname" id="fname" type="text" /&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;label for="lname"&gt;Last Name *&lt;/label&gt; &lt;input name="lname" id="lname" type="text" /&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;label for="email"&gt;Email Address *&lt;/label&gt; &lt;input name="email" id="email" type="text" /&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;input class="right inputnew" type="submit" title="Send" value="Send" /&gt;
        &lt;/div&gt;
      &lt;/fieldset&gt;
    &lt;/form&gt;
    &lt;div id="response"&gt;&lt;/div&gt;
  &lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h4>Form Processor <em>(subscribe.php)</em></h4>
<p>I try to include as much comment as possible to make the code self explanatory.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="php" data-enlighter-linenumbers="false">&lt;?php

  // Put your MailChimp API and List ID hehe
  $api_key = 'ENTER_YOUR_API_KEY_HERE';
  $list_id = 'ENTER_YOUR_LIST_ID_HERE';

  // Let's start by including the MailChimp API wrapper
  include('./inc/MailChimp.php');
  // Then call/use the class
  use \DrewM\MailChimp\MailChimp;
  $MailChimp = new MailChimp($api_key);

  // Submit subscriber data to MailChimp
  // For parameters doc, refer to: http://developer.mailchimp.com/documentation/mailchimp/reference/lists/members/
  // For wrapper's doc, visit: https://github.com/drewm/mailchimp-api
  $result = $MailChimp-&gt;post("lists/$list_id/members", [
              'email_address' =&gt; $_POST["email"],
              'merge_fields'  =&gt; ['FNAME'=&gt;$_POST["fname"], 'LNAME'=&gt;$_POST["lname"]],
              'status'        =&gt; 'subscribed',
            ]);

  if ($MailChimp-&gt;success()) {
    // Success message
    echo "&lt;h4&gt;Thank you, you have been added to our mailing list.&lt;/h4&gt;";
  } else {
    // Display error
    echo $MailChimp-&gt;getLastError();
    // Alternatively you can use a generic error message like:
    // echo "&lt;h4&gt;Please try again.&lt;/h4&gt;";
  }
?&gt;</pre>
<h3>Download</h3>
<p><a href="https://github.com/sunarlim/mailchimp-subscribe-api-v3/archive/master.zip">Click here to download</a> the basic files to create MailChimp subscribe form on your website. Alternatively, you can also <a href="https://github.com/sunarlim/mailchimp-subscribe-api-v3" target="_blank" rel="noopener">visit the GitHub repository</a>.</p>
<h3>Coming Soon Templates</h3>
<p>The MailChimp subscribe form example only includes basic HTML page. If you are thinking of using it for your upcoming site, and you have limited resources to create the page design, check out my list of <a title="5 Clean and Free Coming Soon Page Templates with Email Subscription Form" href="https://sunarlim.com/2014/05/5-clean-and-free-coming-soon-page-templates/">5 Clean and Free Coming Soon Page Templates</a> and <a title="ThemeForest &gt; Site Templates &gt; Specialty Pages &gt; Under Construction" href="http://themeforest.net/category/site-templates/specialty-pages/under-construction?ref=mayksyu" target="_blank" rel="noopener">Coming Soon &amp; Under Construction Templates on ThemeForest</a>.</p>
<p>The post <a href="https://sunarlim.com/2017/01/mailchimp-subscribe-form-php-jquery-api3/">MailChimp Subscribe Form with PHP, jQuery and AJAX (API 3.0)</a> appeared first on <a href="https://sunarlim.com">Michael Sunarlim</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sunarlim.com/2017/01/mailchimp-subscribe-form-php-jquery-api3/feed/</wfw:commentRss>
			<slash:comments>38</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2591</post-id>	</item>
		<item>
		<title>MailChimp Subscribe Form with PHP, jQuery and AJAX</title>
		<link>https://sunarlim.com/2014/04/mailchimp-sign-form-php-jquery-ajax/</link>
					<comments>https://sunarlim.com/2014/04/mailchimp-sign-form-php-jquery-ajax/#comments</comments>
		
		<dc:creator><![CDATA[Michael]]></dc:creator>
		<pubDate>Mon, 28 Apr 2014 10:18:26 +0000</pubDate>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[mailchimp]]></category>
		<category><![CDATA[php]]></category>
		<guid isPermaLink="false">https://sunarlim.com/?p=1008</guid>

					<description><![CDATA[<p>I am pretty sure I have mentioned somewhere in this blog or tweets of how I love MailChimp or and would recommend it for any business wanting to untap their email marketing potential. You can start with zero investment and only start paying when you are completely confident it is very worthy. MailChimp provides a... <span class="more"><a class="more-link" href="https://sunarlim.com/2014/04/mailchimp-sign-form-php-jquery-ajax/">Continue reading <span class="meta-nav">&#8594;</span></a></span></p>
<p>The post <a href="https://sunarlim.com/2014/04/mailchimp-sign-form-php-jquery-ajax/">MailChimp Subscribe Form with PHP, jQuery and AJAX</a> appeared first on <a href="https://sunarlim.com">Michael Sunarlim</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>I am pretty sure I have mentioned somewhere in this blog or tweets of how I love <strong><a title="MailChimp" href="http://mailchimp.com" target="_blank" rel="noopener">MailChimp</a></strong> or and would recommend it for any business wanting to untap their email marketing potential. You can start with zero investment and only start paying when you are completely confident it is very worthy.</p>
<p>MailChimp provides a good tool to generate your custom sign up form which will serve most requirements well. Some customers however, want a fully custom form or integrate it with existing template they already own. Today I am going to share a quick tutorial in how to integrate HTML form with MailChimp API using PHP and jQuery.</p>
<h3>MailChimp Subscribe Form Features</h3>
<p>What will it do?</p>
<ul>
<li>Validate field contents</li>
<li>Pass the form submission to MailChimp and add the record to your list</li>
<li>Basic fallback method for very, very old browser that does not have JavaScript activated</li>
<li>Five minutes setup</li>
</ul>
<p><span id="more-1008"></span></p>
<h3>Tools/Credits</h3>
<ol>
<li><a title="jQuery" href="http://jquery.com/" target="_blank" rel="noopener">jQuery</a></li>
<li><a title="jQuery Validation" href="http://jqueryvalidation.org/" target="_blank" rel="noopener">jQuery Validation Plugin</a></li>
<li><a title="MailChimp API Wrappers" href="http://apidocs.mailchimp.com/api/downloads/#php" target="_blank" rel="noopener">MailChimp PHP API Class</a></li>
</ol>
<h3>The Form Page <em>(index.php)</em></h3>
<p>jQuery will handle the AJAX using <code>$.post</code> method and jQuery Validation plugin will validate the field values including email address format.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="html" data-enlighter-linenumbers="false">&lt;html&gt;
&lt;head&gt;
  &lt;title&gt;MailChimp Sign-Up Form&lt;/title&gt;
  &lt;script type="text/javascript" src="js/jquery-1.11.0.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="js/jquery.validate.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
    $(document).ready(function() {
      // jQuery Validation
      $("#signup").validate({
        // if valid, post data via AJAX
        submitHandler: function(form) {
          $.post("subscribe.php", { fname: $("#fname").val(), lname: $("#lname").val(), email: $("#email").val() }, function(data) {
            $('#response').html(data);
          });
        },
        // all fields are required
        rules: {
          fname: {
            required: true
          },
          lname: {
            required: true
          },
          email: {
            required: true,
            email: true
          }
        }
      });
    });
  &lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
  &lt;div id="wrapper"&gt;
    &lt;form id="signup" class="formee" action="subscribe.php" method="post"&gt;
      &lt;fieldset&gt;
        &lt;legend&gt;Sign Up&lt;/legend&gt;
        &lt;div&gt;
          &lt;label for="fname"&gt;First Name *&lt;/label&gt; &lt;input name="fname" id="fname" type="text" /&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;label for="lname"&gt;Last Name *&lt;/label&gt; &lt;input name="lname" id="lname" type="text" /&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;label for="email"&gt;Email Address *&lt;/label&gt; &lt;input name="email" id="email" type="text" /&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;input class="right inputnew" type="submit" title="Send" value="Send" /&gt;
        &lt;/div&gt;
      &lt;/fieldset&gt;
    &lt;/form&gt;
    &lt;div id="response"&gt;&lt;/div&gt;
  &lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3>Form Processor <em>(subscribe.php)</em></h3>
<p>Our form will connect to MailChimp with the help of <code>MCAPI.class.php</code>. Please make sure you have generated the API key of your account and copied your list ID. MailChimp&#8217;s excellent knowledge base provides the instructions in <a title="MailChimp - Finding or generating your API key" href="http://kb.mailchimp.com/accounts/management/about-api-keys#Finding-or-generating-your-API-key" target="_blank" rel="noopener">how to retrieve your account&#8217;s API key</a> and <a title="MailChimp - Find Your List ID" href="http://kb.mailchimp.com/lists/managing-subscribers/find-your-list-id" target="_blank" rel="noopener">find your list ID</a>.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="php" data-enlighter-linenumbers="false">&lt;?php
  require_once 'inc/MCAPI.class.php';
  $api = new MCAPI('ENTER_YOUR_API_KEY_HERE');
  $merge_vars = array('FNAME'=&gt;$_POST["fname"], 'LNAME'=&gt;$_POST["lname"]);

  // Submit subscriber data to MailChimp
  // For parameters doc, refer to: http://apidocs.mailchimp.com/api/1.3/listsubscribe.func.php
  $retval = $api-&gt;listSubscribe( 'ENTER_YOUR_LIST_ID_HERE', $_POST["email"], $merge_vars, 'html', false, true );

  if ($api-&gt;errorCode){
    echo "&lt;h4&gt;Please try again.&lt;/h4&gt;";
  } else {
    echo "&lt;h4&gt;Thank you, you have been added to our mailing list.&lt;/h4&gt;";
  }
?&gt;</pre>
<p>That&#8217;s it! You can now check on your web server with a few tests and see if they are captured in your MailChimp list.</p>
<h3>Download</h3>
<p>Sample files and structure of this tutorial can be <a title="Tutorial Sample Files" href="https://github.com/sunarlim/mailchimp-subscribe/archive/master.zip">downloaded here</a>. Please share this post if you find it useful using social media buttons below.</p>
<h3>Coming Soon Templates</h3>
<p>My files only include a basic HTML page. If you are thinking of using it for your upcoming site, and you have limited resources to create the page design, check out my list of <a title="5 Clean and Free Coming Soon Page Templates with Email Subscription Form" href="https://sunarlim.com/2014/05/5-clean-and-free-coming-soon-page-templates/">5 Clean and Free Coming Soon Page Templates</a> and <a title="ThemeForest &gt; Site Templates &gt; Specialty Pages &gt; Under Construction" href="http://themeforest.net/category/site-templates/specialty-pages/under-construction?ref=mayksyu" target="_blank" rel="noopener">Coming Soon &amp; Under Construction Templates on ThemeForest</a>.</p>
<hr />
<h2>UPDATE (January 9, 2017)</h2>
<p>I have published updated version of this tutorial to make use of MailChimp&#8217;s newer API 3.0. Please follow the link to read how to create <strong><a href="https://sunarlim.com/2017/01/mailchimp-subscribe-form-php-jquery-api3/">MailChimp Subscribe Form with PHP, jQuery and AJAX (API 3.0)</a></strong>.</p>
<p>The post <a href="https://sunarlim.com/2014/04/mailchimp-sign-form-php-jquery-ajax/">MailChimp Subscribe Form with PHP, jQuery and AJAX</a> appeared first on <a href="https://sunarlim.com">Michael Sunarlim</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sunarlim.com/2014/04/mailchimp-sign-form-php-jquery-ajax/feed/</wfw:commentRss>
			<slash:comments>127</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1008</post-id>	</item>
		<item>
		<title>Ajax Loader Image Generator</title>
		<link>https://sunarlim.com/2008/08/ajax-loader-image-generator/</link>
					<comments>https://sunarlim.com/2008/08/ajax-loader-image-generator/#respond</comments>
		
		<dc:creator><![CDATA[Michael]]></dc:creator>
		<pubDate>Tue, 26 Aug 2008 17:30:57 +0000</pubDate>
				<category><![CDATA[Web Tools]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[web 2.0]]></category>
		<guid isPermaLink="false">http://wp.sunarlim.com.com/?p=118</guid>

					<description><![CDATA[<p>Always having a hard time to find the perfect loader for your AJAX scripts? Then you need to bookmark this site: Ajaxload. Not only it provides a few dozens of animated GIF image for your loader, you can even customize it background and foreground colors. Nice!</p>
<p>The post <a href="https://sunarlim.com/2008/08/ajax-loader-image-generator/">Ajax Loader Image Generator</a> appeared first on <a href="https://sunarlim.com">Michael Sunarlim</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Always having a hard time to find the perfect loader for your AJAX scripts? Then you need to bookmark this site: <a href="http://www.ajaxload.info/" target="_blank">Ajaxload</a>.</p>
<p>Not only it provides a few dozens of animated GIF image for your loader, you can even customize it background and foreground colors. Nice!</p>
<p>The post <a href="https://sunarlim.com/2008/08/ajax-loader-image-generator/">Ajax Loader Image Generator</a> appeared first on <a href="https://sunarlim.com">Michael Sunarlim</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sunarlim.com/2008/08/ajax-loader-image-generator/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">118</post-id>	</item>
	</channel>
</rss>
