<?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/"
	>

<channel>
	<title>FormSpring Blog &#187; FormSpring API</title>
	<atom:link href="http://blog.formspring.com/category/formspringapi/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.formspring.com</link>
	<description>Tips and information for using web forms</description>
	<lastBuildDate>Wed, 17 Mar 2010 13:04:54 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Make Your Event Registration Form Tweet</title>
		<link>http://blog.formspring.com/2009/11/04/make-your-event-registration-form-tweet/</link>
		<comments>http://blog.formspring.com/2009/11/04/make-your-event-registration-form-tweet/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 18:19:46 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[Event Registration Forms]]></category>
		<category><![CDATA[FormSpring API]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[online event registrations]]></category>
		<category><![CDATA[tweetbrite]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://blog.formspring.com/?p=1795</guid>
		<description><![CDATA[Today&#8217;s guest post is from Noah Coffey, a web developer/designer and creator of Tweetbrite.
One of my favorite uses for FormSpring is throwing together a registration form for a conference or event.  As the popularity of Twitter continues to explode, I&#8217;ve noticed more event registration forms asking for attendee&#8217;s Twitter user names. If you are organizing [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.formspring.com%2F2009%2F11%2F04%2Fmake-your-event-registration-form-tweet%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.formspring.com%2F2009%2F11%2F04%2Fmake-your-event-registration-form-tweet%2F" height="61" width="51" /></a></div><p><em>Today&#8217;s guest post is from Noah Coffey, a web developer/designer and creator of Tweetbrite.</em></p>
<p>One of my favorite uses for FormSpring is throwing together a registration form for a conference or event.  As the popularity of Twitter continues to explode, I&#8217;ve noticed more event registration forms asking for attendee&#8217;s Twitter user names. If you are organizing and event, wouldn&#8217;t it be nice if you could automatically tweet every time someone registers for your event?</p>
<p>A site that provides such a service has just integrated with FormSpring. <strong><a id="opqn" title="Tweetbrite" href="http://tweetbrite.com/">Tweetbrite</a></strong> now allows you to connect your FormSpring account to your Twitter account. Every time someone uses your Formspring <a href="http://www.formspring.com/online-registration-form.html" target="_blank">event registration form</a>, Tweetbrite can automatically tweet through your selected Twitter account. For example, &#8220;@johnsmith just registered for MBO 2009.&#8221;</p>
<p><a href="http://blog.formspring.com/wp-content/uploads/2009/11/mboexample.png"><img class="aligncenter size-full wp-image-1796" title="mboexample" src="http://blog.formspring.com/wp-content/uploads/2009/11/mboexample.png" alt="mboexample" width="557" height="74" /></a></p>
<p>To get started, just create a new FormSpring API key from your FormSpring account (<a id="swns" title="tutorial" href="http://tweetbrite.com/formspring_api_help.php">tutorial</a>). Then, head over to Tweetbrite.com, create a free account, and click the big &#8220;Get started&#8221; link once you log-in. A simple setup wizard will guide you through the steps to link your FormSpring account, your Twitter account and create your mashup. Another great feature provided through the use of the FormSpring API key is that you never have to reveal your FormSpring user name or password.</p>
<p><a href="http://blog.formspring.com/wp-content/uploads/2009/11/tweetbritelogin-fix.png"><img class="aligncenter size-full wp-image-1805" title="tweetbritelogin-fix" src="http://blog.formspring.com/wp-content/uploads/2009/11/tweetbritelogin-fix.png" alt="tweetbritelogin-fix" width="592" height="224" /></a><a href="http://blog.formspring.com/wp-content/uploads/2009/11/tweetbritemashup.png"><img class="aligncenter size-full wp-image-1798" title="tweetbritemashup" src="http://blog.formspring.com/wp-content/uploads/2009/11/tweetbritemashup.png" alt="tweetbritemashup" width="662" height="432" /></a></p>
<p>For those interested in details of the integration, the FormSpring API was very intuitive and easy to use. Once Tweetbrite is granted access to a user&#8217;s FormSpring account and a mashup has been created, selected FormSpring forms are checked regularly for new attendee data. Based on which form fields the user selected, Tweetbrite stores the new attendee&#8217;s first and last name and their Twitter user name. Another process tweets the new attendees in the format specified by the user and marks the attendee as having been tweeted (to prevent duplicate tweeting). I wish I could go into more detail about the integration, but the FormSpring API is really straightforward and the documentation is excellent.</p>
<p><a href="http://blog.formspring.com/wp-content/uploads/2009/11/PDA_1422.jpg"><img class="alignleft size-full wp-image-1799" style="margin: 5px;" title="PDA_1422" src="http://blog.formspring.com/wp-content/uploads/2009/11/PDA_1422.jpg" alt="PDA_1422" width="88" height="88" /></a> <em><a href="http://twitter.com/noahwesley" target="_blank">Noah Coffey</a> is a developer trapped inside a web designer. While spending his days enjoying the challenges of web and email design, his true passion lies in side projects developing unique and creative web apps in the social media space. He is also the co-founder of <a href="http://2009.blogindiana.com/" target="_blank">Blog Indiana</a>, an annual blogging and social media conference located in Indianapolis, IN. Noah lives and works in Indianapolis, is married and a proud new father</em><strong>Recent Posts:</strong>
<ul class="recent-posts">
<li><a href="http://blog.formspring.com/2009/12/21/formspring-launches-new-datareport-features/" rel="bookmark" title="December 21, 2009">FormSpring Launches New Data/Report Features</a></li>
<li><a href="http://blog.formspring.com/2009/10/13/how-to-embed-google-analytics-into-your-form/" rel="bookmark" title="October 13, 2009">How To Embed Google Analytics Into Your Form</a></li>
<li><a href="http://blog.formspring.com/2009/10/06/new-multilingual-support-text-on-forms/" rel="bookmark" title="October 6, 2009">New Multilingual Support Text On Forms</a></li>
</ul>
<p><!-- Recent Posts took 52.904 ms --></p>
<h3  class="related_post_title">Other Related Posts</h3><ul class="related_post"><li><a href="http://blog.formspring.com/2009/09/22/the-twall-of-fame/" title="The Twall of Fame">The Twall of Fame</a></li><li><a href="http://blog.formspring.com/2009/03/18/dont-forget-the-emergency-contact-form/" title="Don&#8217;t Forget The Emergency Contact Form">Don&#8217;t Forget The Emergency Contact Form</a></li><li><a href="http://blog.formspring.com/2009/02/16/more-pre-built-web-forms/" title="More Pre-Built Web Forms">More Pre-Built Web Forms</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://blog.formspring.com/2009/11/04/make-your-event-registration-form-tweet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FormSpring Yahoo and Dashboard Widgets</title>
		<link>http://blog.formspring.com/2007/11/14/formspring-yahoo-and-dashboard-widgets/</link>
		<comments>http://blog.formspring.com/2007/11/14/formspring-yahoo-and-dashboard-widgets/#comments</comments>
		<pubDate>Wed, 14 Nov 2007 21:46:20 +0000</pubDate>
		<dc:creator>ade</dc:creator>
				<category><![CDATA[FormSpring API]]></category>
		<category><![CDATA[Mac OS X Dashboard widget]]></category>
		<category><![CDATA[Yahoo Widget]]></category>

		<guid isPermaLink="false">http://www.formspring.com/blog/2007/11/14/formspring-yahoo-and-dashboard-widgets/</guid>
		<description><![CDATA[Now that FormSpring has an API, the fun part begins. How do we use it?
One of the things I like to do is monitor my forms to see if any new data has been collected. I&#8217;d kind of like something that just hangs around in the background, watching the form, and if someone submits a [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.formspring.com%2F2007%2F11%2F14%2Fformspring-yahoo-and-dashboard-widgets%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.formspring.com%2F2007%2F11%2F14%2Fformspring-yahoo-and-dashboard-widgets%2F" height="61" width="51" /></a></div><p>Now that FormSpring has an API, the fun part begins. How do we use it?</p>
<p>One of the things I like to do is monitor my forms to see if any new data has been collected. I&#8217;d kind of like something that just hangs around in the background, watching the form, and if someone submits a form, it lets me know.</p>
<p>Widgets are a perfect application for this, and I put together both a <a href="http://widgets.yahoo.com/gallery/view.php?widget=42692">Yahoo Widget</a> as well as a <a href="http://www.formspring.com/assets/files/dashboard/FormSpring.zip">Mac OS X Dashboard widget</a> that does just what I need.</p>
<p><img src="http://blog.formspring.com/wp-content/uploads/2007/11/widget.png" alt="widget.png" /></p>
<p>If you&#8217;re interested in how the widgets were built so you can customize them on your own, keep reading and I&#8217;ll give a quick overview.</p>
<h2>The Yahoo Widget</h2>
<p>Yahoo Widgets are, essentially, a combination of XML and Javascript. You bundle these files together, and they make up your widget (Full Yahoo Widget documentation can be found <a href="http://widgets.yahoo.com">here</a>).</p>
<p>The file <em>FormSpring.kon</em> contains the XML that defines the widget. I have 2 frames, or views, one to display the form information and the other to allow you to enter your API key. In this file, I also define a timer:</p>
<pre class="xml">
&lt;timer&gt;
    &lt;name&gt;timer&lt;/name&gt;
    &lt;interval&gt;30&lt;/interval&gt;
    &lt;ticking&gt;true&lt;/ticking&gt;
    &lt;onTimerFired&gt;fetchFormInformation();&lt;/onTimerFired&gt;
&lt;/timer&gt;</pre>
<p>I use this so that every 30 minutes, the widget calls the fetchFormInformation() function and, as you can guess from the name, fetches the form information. I&#8217;ve defined that function in the <em>main.js</em> file, and it looks something like this:</p>
<pre class="javascript">
function fetchFormInformation() {

	// get the Form ID and the API Key
	var apiKey = preferences.apiKey.value;
	var formID = preferences.selectedFormID.value;

	// build url for the call
	var location = 'https://www.formspring.com/api/form?api_key=' + apiKey + '&amp;id=' + formID + '&amp;type=json';

	// get that information asynchronously
	var url = new URL();
	url.location = location;
	url.fetchAsync(fetchFormInformationHandler);
}</pre>
<p>Here, I&#8217;m doing a couple of things. First, I get the API Key and the selected Form ID from the preferences (these are stored elsewhere in the widget). I then build the URL for the call, and then grab the information. You&#8217;ll notice I use type=json in the URL so that I get back JSON data.</p>
<p>Yahoo Widgets have a very nice URL object that does most of the heavy lifting for me, and I create a new URL object to do so. As you can see, I&#8217;m fetching this information asynchronously, and I define a handler function (fetchFormInformationHandler) that gets called once the information has been retrieved. Here is an excerpt:</p>
<pre class="javascript">
function fetchFormInformationHandler(url) {

	var data = url.responseData.parseJSON();

	var formData = data.response;

	// populate the form with the new values
	formName.data = formData.name;
	formSubmissionTotal.data = formData.submissions;
	formViews.data = formData.views;
}</pre>
<p>Since I&#8217;ve asked the API for JSON data (using type=json in the URL), the first thing I need to do is convert it to a format I can use. In the widget, I&#8217;ve included a file called <em>json.js</em> which has a nice function that does this for me. So, I get the response text from the URL object, then immediately convert that from JSON into a Javascript object.</p>
<p>From there, it&#8217;s trivial to update the various interface elements with the data I just fetched.</p>
<h2>The Dashboard Widget</h2>
<p>For the Mac OS X Dashboard widget, I did essentially the same thing. In this case, I needed to use a different method to parse the JSON data. For example, in the file <em>FormSpring.js</em>, I have a similar method to the Yahoo Widget called fetchFormInformation(). Unlike the Yahoo Widget, though, I don&#8217;t need a handler, this one is all self contained:</p>
<pre class="javascript">
function fetchFormInformation() {

	// get the Form ID and the API Key
	var apiKey = $('apiKey').value;
	var formID = $('formSelect').options[$('formSelect').selectedIndex].value;

	var url = 'https://www.formspring.com/api/form';

	// get the information for this form, then change the front of the widget
	new Ajax.Request(url,
	  {
		method:'get',
		parameters: {api_key: apiKey, id: formID, type: 'json'},
		onSuccess: function(transport) {

			// get the JSON data array
			data = transport.responseText.evalJSON();

			// use the response data to populate the widget
			formData = data.response;

			$('formResponses').innerHTML = formData.submissions;
			$('formName').innerHTML = formData.name;

			if (formData.views)
				$('formViews').innerHTML = formData.views;
		},
		onFailure: function(){ alert('Something went wrong...') }
	  });
}</pre>
<p>Here, I&#8217;m using an Ajax request method to get the form information. Once I have it, I do the same thing as with the Yahoo Widget: I parse the JSON data (with evalJSON()), then update the interface with the information.</p>
<p>Once you get the hang of it, it&#8217;s pretty easy. Yahoo and Apple both have excellent documentation and plenty of examples. In addition, you can download the source code (<a href="http://badge.ydp.clientapps.yahoo.com/badge/widgets/dl/widget/42692/gen/FormSpring.widget">Yahoo Widget source here</a> and <a href="http://www.formspring.com/assets/files/dashboard/FormSpringProject.zip">Dashboard widget here</a>) of these widgets, crack them open, and try your hand at creating your own.</p>
<p>Have fun, and feel free to add any comments or questions below.<strong>Recent Posts:</strong>
<ul class="recent-posts">
<li><a href="http://blog.formspring.com/2009/12/21/formspring-launches-new-datareport-features/" rel="bookmark" title="December 21, 2009">FormSpring Launches New Data/Report Features</a></li>
<li><a href="http://blog.formspring.com/2009/11/04/make-your-event-registration-form-tweet/" rel="bookmark" title="November 4, 2009">Make Your Event Registration Form Tweet</a></li>
<li><a href="http://blog.formspring.com/2009/10/13/how-to-embed-google-analytics-into-your-form/" rel="bookmark" title="October 13, 2009">How To Embed Google Analytics Into Your Form</a></li>
</ul>
<p><!-- Recent Posts took 52.717 ms --></p>
<h3  class="related_post_title">Other Related Posts</h3><ul class="related_post"><li><a href="http://blog.formspring.com/2009/11/04/make-your-event-registration-form-tweet/" title="Make Your Event Registration Form Tweet">Make Your Event Registration Form Tweet</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://blog.formspring.com/2007/11/14/formspring-yahoo-and-dashboard-widgets/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using Google Calendar with the FormSpring API</title>
		<link>http://blog.formspring.com/2007/09/07/using-google-calendar-with-the-formspring-api/</link>
		<comments>http://blog.formspring.com/2007/09/07/using-google-calendar-with-the-formspring-api/#comments</comments>
		<pubDate>Fri, 07 Sep 2007 21:10:18 +0000</pubDate>
		<dc:creator>ade</dc:creator>
				<category><![CDATA[FormSpring API]]></category>

		<guid isPermaLink="false">http://www.formspring.com/blog/2007/09/07/using-google-calendar-with-the-formspring-api/</guid>
		<description><![CDATA[This is the last of three Google mashup articles this week for programmers who want to explore the new FormSpring API. If you haven&#8217;t seen them yet, take a look at the Google Maps mashup and the Google Spreadsheets mashup.
This one will take data submitted on a FormSpring form and create new events in Google [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.formspring.com%2F2007%2F09%2F07%2Fusing-google-calendar-with-the-formspring-api%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.formspring.com%2F2007%2F09%2F07%2Fusing-google-calendar-with-the-formspring-api%2F" height="61" width="51" /></a></div><p>This is the last of three Google mashup articles this week for programmers who want to explore the new <a href="http://www.formspring.com/api.html">FormSpring API</a>. If you haven&#8217;t seen them yet, take a look at the <a href="http://blog.formspring.com/2007/09/05/using-google-maps-with-the-formspring-api/">Google Maps mashup</a> and the <a href="http://blog.formspring.com/2007/09/06/using-google-spreadsheets-with-the-formspring-api/">Google Spreadsheets mashup</a>.</p>
<p>This one will take data submitted on a FormSpring form and create new events in <a href="http://www.google.com/calendar">Google Calendar</a>.  This might be helpful if you want to use your calendar to track registrations for a workshop series, or if your customers are submitting requests to schedule service.  Once integration is setup, new events can appear on the calendar soon after a form is submitted.  You can also extend the example so events aren&#8217;t created as soon as the form is submitted &#8212; you can create a hidden date/time field on your form that is for administrative use only, and have events created only when that field has been set.</p>
<p><img src='http://blog.formspring.com/wp-content/uploads/2007/09/cal1.png' alt='cal1.png' /></p>
<p>Feel free to <a href="http://www.formspring.com/assets/files/api/FormSpring-GoogleCalendar.zip">download the example PHP code</a> and follow along. The example code uses the <a href="http://framework.zend.com/">Zend Framework PHP Client Library</a> to access the Google Calendar API. You will need to <a href="http://framework.zend.com/download">download the Zend framework</a> in order to use this.</p>
<p>To get started you&#8217;ll need to have a form with at least one date field that contains the event start time.  You&#8217;ll also need to <a href="https://www.formspring.com/admin/apiKey/main">create a FormSpring API key</a> that has data access to your form.</p>
<p>In this example we have a date field labeled &#8220;Start Time&#8221;, another labeled &#8220;End Time&#8221; and a text field labeled &#8220;Event Title&#8221;.  We&#8217;ll map these to the appropriate values when creating a calendar event.  More information about all the event attributes can be found in the <a href="http://code.google.com/apis/calendar/developers_guide_protocol.html">Google Calendar API documentation</a>.</p>
<p>The script starts by getting a list of fields on the form, looking for the fields we need to create the event, then mapping the field id to the event attribute.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$field_labels</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Event Title'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'start'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Start Time'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'end'</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'End Time'</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Get information on the FormSpring form</span>
<span style="color: #000088;">$form</span> <span style="color: #339933;">=</span> FormSpring<span style="color: #339933;">::</span><span style="color: #004000;">request</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$api_key</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'form'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$form_id</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Get form field ids for the title, start and end fields</span>
<span style="color: #000088;">$fields</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'fields'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$field</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$field_labels</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$label</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$field</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'label'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$label</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$fields</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$field</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$key</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now we can start searching submitted data and creating events.  As with yesterday&#8217;s example, the assumption is made that this script will be scheduled to run in cron on a regular basis.  We&#8217;ll need some mechanism to make sure that we don&#8217;t create new events for old submissions.  For the sake of simplicity, in the example we do that by downloading the prior day&#8217;s worth of submissions and assume that the script will only run once a day. The min_time and max_time parameters (which search against the submission date and time for each record) can easily be changed to do this on an hourly basis, or we can locally store the unique id of the last submission so the script isn&#8217;t tied to the date and time it&#8217;s run.</p>
<p>When downloading the submitted data only a pre-defined number of results (25 by default) are returned at each time, and we&#8217;ll need to make multiple requests to the API to download each &#8220;page&#8221; of results.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Loop through each page, making one query per page of data</span>
<span style="color: #000088;">$pages</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$parameters</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'page'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;=</span> <span style="color: #000088;">$pages</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Get submitted data</span>
    <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> FormSpring<span style="color: #339933;">::</span><span style="color: #004000;">request</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$api_key</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'data'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$parameters</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Update the number of pages</span>
    <span style="color: #000088;">$pages</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pages'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Iterate over each entry</span>
    <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'submissions'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$submission</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// ....</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Increment the page # for the next request</span>
    <span style="color: #000088;">$parameters</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'page'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">++;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Within the submission loop, we create a new event for each form submission, then add that to the calendar using the Zend library.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Iterate over each data item to get the event information</span>
<span style="color: #000088;">$event</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$submission</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'data'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fields</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'field'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$field</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$fields</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'field'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$event</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$field</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'value'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Create a new calendar event</span>
<span style="color: #000088;">$newEvent</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$gdataCal</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">newEventEntry</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$newEvent</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$gdataCal</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">newTitle</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$event</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$when</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$gdataCal</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">newWhen</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$when</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">startTime</span> <span style="color: #339933;">=</span> date3339<span style="color: #009900;">&#40;</span><span style="color: #000088;">$event</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'start'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$when</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">endTime</span> <span style="color: #339933;">=</span> date3339<span style="color: #009900;">&#40;</span><span style="color: #000088;">$event</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'end'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$newEvent</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">when</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$when</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Add the event to the calendar</span>
<span style="color: #000088;">$createdEvent</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$gdataCal</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">insertEvent</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$newEvent</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>You&#8217;ll need to refresh your calendar to view new events, and can edit them just like you would any other ones.</p>
<p>That&#8217;s it for our series on FormSpring-Google mashups.  Feel free to comment below if you have any questions, ideas for mashups you&#8217;d like to see, or links to ones that you&#8217;ve built yourself.<strong>Recent Posts:</strong>
<ul class="recent-posts">
<li><a href="http://blog.formspring.com/2009/12/21/formspring-launches-new-datareport-features/" rel="bookmark" title="December 21, 2009">FormSpring Launches New Data/Report Features</a></li>
<li><a href="http://blog.formspring.com/2009/11/04/make-your-event-registration-form-tweet/" rel="bookmark" title="November 4, 2009">Make Your Event Registration Form Tweet</a></li>
<li><a href="http://blog.formspring.com/2009/10/13/how-to-embed-google-analytics-into-your-form/" rel="bookmark" title="October 13, 2009">How To Embed Google Analytics Into Your Form</a></li>
</ul>
<p><!-- Recent Posts took 55.234 ms --></p>
<h3  class="related_post_title">Other Interesting Posts</h3><ul class="related_post"><li><a href="http://blog.formspring.com/2009/09/15/continued-learning-with-formspring/" title="Continued Learning With FormSpring">Continued Learning With FormSpring</a></li><li><a href="http://blog.formspring.com/2009/06/23/adding-form-field-variables-to-e-mail-subject-lines/" title="Adding Form Field Variables to E-mail Subject Lines">Adding Form Field Variables to E-mail Subject Lines</a></li><li><a href="http://blog.formspring.com/2007/07/25/new-version-of-formspring-set-to-launch/" title="New Version of FormSpring Set to Launch">New Version of FormSpring Set to Launch</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://blog.formspring.com/2007/09/07/using-google-calendar-with-the-formspring-api/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using Google Spreadsheets with the FormSpring API</title>
		<link>http://blog.formspring.com/2007/09/06/using-google-spreadsheets-with-the-formspring-api/</link>
		<comments>http://blog.formspring.com/2007/09/06/using-google-spreadsheets-with-the-formspring-api/#comments</comments>
		<pubDate>Thu, 06 Sep 2007 20:59:16 +0000</pubDate>
		<dc:creator>ade</dc:creator>
				<category><![CDATA[FormSpring API]]></category>

		<guid isPermaLink="false">http://www.formspring.com/blog/2007/09/06/using-google-spreadsheets-with-the-formspring-api/</guid>
		<description><![CDATA[This is the second of three Google mashup articles this week for programmers who want to explore the new FormSpring API.  If you haven&#8217;t seen it yet, take a look at yesterday&#8217;s Google Maps mashup. 
Today&#8217;s mashup involves updating a Google Spreadsheet with collected form data.  It might be advantageous to do this [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.formspring.com%2F2007%2F09%2F06%2Fusing-google-spreadsheets-with-the-formspring-api%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.formspring.com%2F2007%2F09%2F06%2Fusing-google-spreadsheets-with-the-formspring-api%2F" height="61" width="51" /></a></div><p>This is the second of three Google mashup articles this week for programmers who want to explore the new <a href="http://www.formspring.com/api.html">FormSpring API</a>.  If you haven&#8217;t seen it yet, take a look at yesterday&#8217;s <a href="http://blog.formspring.com/2007/09/05/using-google-maps-with-the-formspring-api/">Google Maps mashup</a>. </p>
<p>Today&#8217;s mashup involves updating a <a href="http://docs.google.com/">Google Spreadsheet</a> with collected form data.  It might be advantageous to do this over regularly exporting data to Excel or another spreadsheet in a manual fashion &#8212; once the integration is setup, you can work within an online spreadsheet and see new rows added shortly after a form&#8217;s submitted.  </p>
<p>Feel free to <a href="http://www.formspring.com/assets/files/api/FormSpring-GoogleSpreadsheets.zip">download the PHP code</a> and follow along.  The example code uses the <a href="http://framework.zend.com/">Zend Framework PHP Client Library</a> to access the Google Spreadsheets API.  You&#8217;ll need to <a href="http://framework.zend.com/download">download the Zend framework</a> in order to use this.  </p>
<p>To get started, sign up for a Google account and create a spreadsheet that will be used to store data collected in the FormSpring form.  You&#8217;ll also need to <a href="https://www.formspring.com/admin/apiKey/main">create a FormSpring API key</a> that has <em>data</em> access to your form.  In the spreadsheet, create a header row that matches the field labels in your form.  The script will look at that header row to figure out what data should be copied.  For example, if the script sees a column titled &#8220;First Name&#8221;, the data from the field labeled &#8220;First Name&#8221; will be added to the appropriate cell.</p>
<p><img src='http://blog.formspring.com/wp-content/uploads/2007/09/ssheet1.png' alt='ssheet1.png' /></p>
<p>In the PHP script (example.php in the download), we&#8217;ll first use the Zend library to log in to Google using a username and password:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$authService</span> <span style="color: #339933;">=</span> Zend_Gdata_Spreadsheets<span style="color: #339933;">::</span><span style="color: #004000;">AUTH_SERVICE_NAME</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$httpClient</span> <span style="color: #339933;">=</span> Zend_Gdata_ClientLogin<span style="color: #339933;">::</span><span style="color: #004000;">getHttpClient</span><span style="color: #009900;">&#40;</span>
    <span style="color: #000088;">$google_username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$google_password</span><span style="color: #339933;">,</span> <span style="color: #000088;">$authService</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$gdClient</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Gdata_Spreadsheets<span style="color: #009900;">&#40;</span><span style="color: #000088;">$httpClient</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The example gets a list of all the spreadsheets in the account, and finds the one we want to update.  Once the spreadsheet name is found, we save the key to use later.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$feed</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$gdClient</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getSpreadsheetFeed</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">entries</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$entry</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$entry</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">text</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$spreadsheet_name</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #990000;">split</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$entry</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$spreadsheet_key</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$id</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>We&#8217;ll need to do the same thing to find the right worksheet within the spreadsheet, but can assume that most of the time the first worksheet will be used.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Gdata_Spreadsheets_DocumentQuery<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setSpreadsheetKey</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$spreadsheet_key</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$feed</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$gdClient</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getWorksheetFeed</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">entries</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$entry</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>
        <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$worksheet_name</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> 
        <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$worksheet_name</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$entry</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">text</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$worksheet_name</span><span style="color: #009900;">&#41;</span> 
    <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>        
        <span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #990000;">split</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$entry</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$worksheet_id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$id</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">8</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000088;">$i</span><span style="color: #339933;">++;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Once we&#8217;ve found the worksheet, we can get the header row and save the contents to try to match up to the form field labels.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$header_cells</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Gdata_Spreadsheets_CellQuery<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setSpreadsheetKey</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$spreadsheet_key</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setWorksheetId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$worksheet_id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setMaxRow</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$feed</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$gdClient</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCellFeed</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">entries</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$entry</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$header_cells</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$entry</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">content</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">text</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now we query the FormSpring API in order to get information about the form, including a list of fields on the form with their labels and id.  We&#8217;ll loop over the list of fields and find the ones that exist in the spreadsheet.  We&#8217;ll also store a modified version of the field name which is used by the Google Spreadsheets API to reference each column (e.g. firstname instead of First Name).</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Get information on the FormSpring form</span>
<span style="color: #000088;">$form</span> <span style="color: #339933;">=</span> FormSpring<span style="color: #339933;">::</span><span style="color: #004000;">request</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$api_key</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'form'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$form_id</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Map form field ids to worksheet column names</span>
<span style="color: #000088;">$fields</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'fields'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$field</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$field</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'label'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$header_cells</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$fields</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$field</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$field</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'label'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>After figuring out how to match up form fields with spreadsheet cells, we can start fetching submitted data.  Assuming that this script will be scheduled to run in cron on a regular basis, we&#8217;ll need some mechanism to make sure that we don&#8217;t add old data to an existing spreadsheet.  For the sake of simplicity, in the example we do that by downloading the prior day&#8217;s worth of submissions and assume that the script will only run once a day.  The min_time and max_time parameters (which search against the submission date and time for each record) can easily be changed to do this on an hourly basis, or even better, we can locally store the unique id of the last submission so that we know the same submission is never added to the spreadsheet twice.</p>
<p>When downloading the submitted data only a pre-defined number of results (25 by default) are returned at each time, and we&#8217;ll need to make multiple requests to the API to download each &#8220;page&#8221; of results.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Loop through each page, making one query per page of data</span>
<span style="color: #000088;">$pages</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$parameters</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'page'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;=</span> <span style="color: #000088;">$pages</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Get submitted data</span>
    <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> FormSpring<span style="color: #339933;">::</span><span style="color: #004000;">request</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$api_key</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'data'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$parameters</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Update the number of pages</span>
    <span style="color: #000088;">$pages</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pages'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Iterate over each entry</span>
    <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'submissions'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$submission</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// ....</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Increment the page # for the next request</span>
    <span style="color: #000088;">$parameters</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'page'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">++;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Within the submission loop, we build a row of data that will get inserted into the spreadsheet.  The row is stored as an array with the column name as the key and the submission data as the value.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$submission</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'data'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fields</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'field'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$col</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$fields</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'field'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$col</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'value'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Once the row is created, it can be added to the spreadsheet using the Zend library.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$entry</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$gdClient</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">insertRow</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #339933;">,</span> <span style="color: #000088;">$spreadsheet_key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$worksheet_id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$entry</span> instanceof Zend_Gdata_Spreadsheets_ListEntry<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;added row <span style="color: #006699; font-weight: bold;">{$entry-&gt;id-&gt;text}</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>You should see the data update within the Google Spreadsheets interface in real time while the script runs, and can be sorted, formatted and revised just like any other spreadsheet.</p>
<p>Feel free to comment below if you have any questions about this example.  Check back tomorrow for another Google mashup example.<strong>Recent Posts:</strong>
<ul class="recent-posts">
<li><a href="http://blog.formspring.com/2009/12/21/formspring-launches-new-datareport-features/" rel="bookmark" title="December 21, 2009">FormSpring Launches New Data/Report Features</a></li>
<li><a href="http://blog.formspring.com/2009/11/04/make-your-event-registration-form-tweet/" rel="bookmark" title="November 4, 2009">Make Your Event Registration Form Tweet</a></li>
<li><a href="http://blog.formspring.com/2009/10/13/how-to-embed-google-analytics-into-your-form/" rel="bookmark" title="October 13, 2009">How To Embed Google Analytics Into Your Form</a></li>
</ul>
<p><!-- Recent Posts took 54.796 ms --></p>
<h3  class="related_post_title">Other Interesting Posts</h3><ul class="related_post"><li><a href="http://blog.formspring.com/2010/03/05/five-minutes-with-noah-coffey/" title="Five Minutes with Noah Coffey">Five Minutes with Noah Coffey</a></li><li><a href="http://blog.formspring.com/2009/07/02/out-of-office-friday-july-3rd/" title="Out of Office Friday, July 3rd">Out of Office Friday, July 3rd</a></li><li><a href="http://blog.formspring.com/2009/11/04/make-your-event-registration-form-tweet/" title="Make Your Event Registration Form Tweet">Make Your Event Registration Form Tweet</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://blog.formspring.com/2007/09/06/using-google-spreadsheets-with-the-formspring-api/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Using Google Maps with the FormSpring API</title>
		<link>http://blog.formspring.com/2007/09/05/using-google-maps-with-the-formspring-api/</link>
		<comments>http://blog.formspring.com/2007/09/05/using-google-maps-with-the-formspring-api/#comments</comments>
		<pubDate>Wed, 05 Sep 2007 22:04:30 +0000</pubDate>
		<dc:creator>ade</dc:creator>
				<category><![CDATA[FormSpring API]]></category>

		<guid isPermaLink="false">http://www.formspring.com/blog/2007/09/05/using-google-maps-with-the-formspring-api/</guid>
		<description><![CDATA[The FormSpring API is now live, and available to anyone with an account.  To create a key to use with your forms, log in to the admin interface, go to Your Account then click on the API section.  We&#8217;ve put together some online documentation to help you get started, along with some example [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.formspring.com%2F2007%2F09%2F05%2Fusing-google-maps-with-the-formspring-api%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.formspring.com%2F2007%2F09%2F05%2Fusing-google-maps-with-the-formspring-api%2F" height="61" width="51" /></a></div><p>The FormSpring API is now live, and available to anyone with an account.  To create a key to use with your forms, log in to the <a href="https://www.formspring.com/admin/">admin interface</a>, go to <em>Your Account</em> then click on the <em>API</em> section.  We&#8217;ve put together some <a href="http://www.formspring.com/api.html">online documentation</a> to help you get started, along with some <a href="http://www.formspring.com/assets/files/api/FormSpringAPI-PHP.zip">example PHP code</a> (more languages coming soon).</p>
<p>In this article, I&#8217;m going to walk you through an overview of the creation of a mashup application that uses the FormSpring and Google Maps APIs.  It&#8217;s the first of three Google mashups that we&#8217;ve put together this week to help programmers better understand the API, and hopefully spark some creative ideas on ways you can use FormSpring with other web applications.  Today&#8217;s mashup will take addresses submitted with a form and display the locations on an interactive map.  For example, if you create a registration form for an event you&#8217;re holding, you can use this to easily display where your registrants are coming from.  Feel free to <a href="http://www.formspring.com/assets/files/api/FormSpring-GoogleMaps.zip">download the source code</a> and follow along.</p>
<p>The first thing to do is create your form with the appropriate address fields.  The one used in this example has text fields for address, city and zip code, and a select list for U.S. states.</p>
<p><img src="http://blog.formspring.com/wp-content/uploads/2007/09/maps1.png" alt="maps1.png" /></p>
<p>Now you&#8217;ll need to create an API key with <em>data</em> access to that form.  Log into your account as described above to create the key.  You&#8217;ll also need to <a href="http://www.google.com/apis/maps/signup.html">create a Google Maps API key</a> in order to geocode the addresses and display the map.</p>
<p>There are a lot of ways to use the <a href="http://www.google.com/apis/maps/documentation/">Google Maps API</a>, but what we&#8217;re going to do in this example is create a static HTML file with JavaScript code that displays the map, while the points on the map are fetched from an XML file.  The file will be generated with a PHP script that gets submitted form entries, sends each address to the Google Map geocoder to translate them to a latitude/longitude point, and outputs something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;markers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;marker</span> <span style="color: #000066;">lat</span>=<span style="color: #ff0000;">&quot;39.905285&quot;</span> <span style="color: #000066;">lng</span>=<span style="color: #ff0000;">&quot;-86.087273&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;marker</span> <span style="color: #000066;">lat</span>=<span style="color: #ff0000;">&quot;39.905186&quot;</span> <span style="color: #000066;">lng</span>=<span style="color: #ff0000;">&quot;-86.051196&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;marker</span> <span style="color: #000066;">lat</span>=<span style="color: #ff0000;">&quot;39.926901&quot;</span> <span style="color: #000066;">lng</span>=<span style="color: #ff0000;">&quot;-86.066278&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/markers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>In the PHP script (data.php in the download), we&#8217;ll first make a request to the API&#8217;s <em>form</em> method to get information about all the fields on the form, in order to map field ids to labels (e.g., so we know the City field is the field with ID 100001).</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Get information on the FormSpring form</span>
<span style="color: #000088;">$form</span> <span style="color: #339933;">=</span> FormSpring<span style="color: #339933;">::</span><span style="color: #004000;">request</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$api_key</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'form'</span><span style="color: #339933;">,</span>
    <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$form_id</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Map field ids to labels</span>
<span style="color: #000088;">$fields</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'fields'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$field</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$fields</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$field</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$field</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'label'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now we make a second request to the API to retrieve submitted entries from the form:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Get the 1st page of submitted data for the form</span>
<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> FormSpring<span style="color: #339933;">::</span><span style="color: #004000;">request</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$api_key</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'data'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$form_id</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Iterate over each entry</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'submissions'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$submission</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// ...</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>As we loop over each submission we create a geocoder query string by combining address, city, state and zip code values.  We&#8217;re going to request a CSV formatted response from the geocoder, which is described in detail <a href="http://www.google.com/apis/maps/documentation/#Geocoding_HTTP_Request">here</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Make a request to Google's geocoder to get address lat/long</span>
<span style="color: #000088;">$csv</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://maps.google.com/maps/geo?q='</span> <span style="color: #339933;">.</span>
    <span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$address</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&amp;output=csv&amp;key='</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$maps_key</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Parse the first line of the CSV response</span>
<span style="color: #000088;">$lines</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$csv</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$res</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lines</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Add this point if the status code was successful</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$res</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">200</span><span style="color: #009900;">&#41;</span>
    <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">'&lt;marker lat=&quot;'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$res</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; lng=&quot;'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$res</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; /&gt;'</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now that the XML file is being generated with points for each address, you need to create the HTML and JavaScript to display the map.  In the HTML file, you can start with the <a href="http://www.google.com/apis/maps/documentation/#The_Hello_World_of_Google_Maps">Hello World example</a> from the Google Maps API documentation.  Now use the GDownloadUrl() method to point to data.php, parse the XML and add a marker for each entry:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">GDownloadUrl<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;data.php&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #339933;">,</span> responseCode<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> xml <span style="color: #339933;">=</span> GXml.<span style="color: #660066;">parse</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> markers <span style="color: #339933;">=</span> xml.<span style="color: #660066;">documentElement</span>.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;marker&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> markers.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> point <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> GLatLng<span style="color: #009900;">&#40;</span>
            parseFloat<span style="color: #009900;">&#40;</span>markers<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;lat&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            parseFloat<span style="color: #009900;">&#40;</span>markers<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;lng&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        map.<span style="color: #660066;">addOverlay</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> GMarker<span style="color: #009900;">&#40;</span>point<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Once that&#8217;s done, you should have a map that looks something like the image below (this shows all the Starbucks within a 2 mile radius of our offices):</p>
<p><img src='http://blog.formspring.com/wp-content/uploads/2007/09/maps2.png' alt='maps2.png' /></p>
<p>If you use this on a live site, you might want to setup a cron job to run the PHP script and save the output to a static XML file every few minutes, then point to that file instead.  That would speed up the rendering process dramatically, and ensure that you don&#8217;t reach the maximum number of requests for your API keys if the site gets heavy traffic.</p>
<p>That&#8217;s all.  Feel free to comment if you have any questions or suggestions.  Check back tomorrow for another example.</p>
<p><strong>Recent Posts:</strong>
<ul class="recent-posts">
<li><a href="http://blog.formspring.com/2009/12/21/formspring-launches-new-datareport-features/" rel="bookmark" title="December 21, 2009">FormSpring Launches New Data/Report Features</a></li>
<li><a href="http://blog.formspring.com/2009/11/04/make-your-event-registration-form-tweet/" rel="bookmark" title="November 4, 2009">Make Your Event Registration Form Tweet</a></li>
<li><a href="http://blog.formspring.com/2009/10/13/how-to-embed-google-analytics-into-your-form/" rel="bookmark" title="October 13, 2009">How To Embed Google Analytics Into Your Form</a></li>
</ul>
<p><!-- Recent Posts took 55.406 ms --></p>
<h3  class="related_post_title">Other Interesting Posts</h3><ul class="related_post"><li><a href="http://blog.formspring.com/2010/02/26/meet-us-at-sxsw-at-the-sxsbw-happy-hour/" title="Meet Us at SXSW at the SXSBW Happy Hour">Meet Us at SXSW at the SXSBW Happy Hour</a></li><li><a href="http://blog.formspring.com/2007/07/25/new-version-of-formspring-set-to-launch/" title="New Version of FormSpring Set to Launch">New Version of FormSpring Set to Launch</a></li><li><a href="http://blog.formspring.com/2009/12/21/formspring-launches-new-datareport-features/" title="FormSpring Launches New Data/Report Features">FormSpring Launches New Data/Report Features</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://blog.formspring.com/2007/09/05/using-google-maps-with-the-formspring-api/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Looking for FormSpring API Beta Testers</title>
		<link>http://blog.formspring.com/2007/08/20/looking-for-formspring-api-beta-testers/</link>
		<comments>http://blog.formspring.com/2007/08/20/looking-for-formspring-api-beta-testers/#comments</comments>
		<pubDate>Mon, 20 Aug 2007 16:00:41 +0000</pubDate>
		<dc:creator>ade</dc:creator>
				<category><![CDATA[FormSpring API]]></category>

		<guid isPermaLink="false">http://www.formspring.com/blog/2007/08/20/looking-for-formspring-api-beta-testers/</guid>
		<description><![CDATA[We&#8217;ve been working on creating the new FormSpring API, and are currently looking for beta testers to try it out and give us feedback.  The API will let programmers add, edit and retrieve data stored within your FormSpring account, and currently returns data in XML, JSON and serialized PHP.
If you&#8217;re interested, please read through [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.formspring.com%2F2007%2F08%2F20%2Flooking-for-formspring-api-beta-testers%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.formspring.com%2F2007%2F08%2F20%2Flooking-for-formspring-api-beta-testers%2F" height="61" width="51" /></a></div><p>We&#8217;ve been working on creating the new FormSpring API, and are currently looking for beta testers to try it out and give us feedback.  The API will let programmers add, edit and retrieve data stored within your FormSpring account, and currently returns data in XML, JSON and serialized PHP.</p>
<p>If you&#8217;re interested, please read through the <a href="http://www.formspring.com/api.html">API documentation</a> and fill out this <a href="http://www.formspring.com/forms/?95811-MFFLyWs8Fd">contact form</a> so we can give you access to start using the API.</p>
<p>The full launch of the API is tentatively scheduled for mid-September.  Stay tuned for more news.<strong>Recent Posts:</strong>
<ul class="recent-posts">
<li><a href="http://blog.formspring.com/2009/12/21/formspring-launches-new-datareport-features/" rel="bookmark" title="December 21, 2009">FormSpring Launches New Data/Report Features</a></li>
<li><a href="http://blog.formspring.com/2009/11/04/make-your-event-registration-form-tweet/" rel="bookmark" title="November 4, 2009">Make Your Event Registration Form Tweet</a></li>
<li><a href="http://blog.formspring.com/2009/10/13/how-to-embed-google-analytics-into-your-form/" rel="bookmark" title="October 13, 2009">How To Embed Google Analytics Into Your Form</a></li>
</ul>
<p><!-- Recent Posts took 54.604 ms --></p>
<h3  class="related_post_title">Other Interesting Posts</h3><ul class="related_post"><li><a href="http://blog.formspring.com/2006/04/24/personalized-responses/" title="Personalized responses">Personalized responses</a></li><li><a href="http://blog.formspring.com/2009/07/13/linking-vs-embedding-vs-html/" title="Linking Vs. Embedding Vs. HTML">Linking Vs. Embedding Vs. HTML</a></li><li><a href="http://blog.formspring.com/2007/08/29/formspring-user-profile-custom-fitness-concepts/" title="FormSpring User Profile: Custom Fitness Concepts">FormSpring User Profile: Custom Fitness Concepts</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://blog.formspring.com/2007/08/20/looking-for-formspring-api-beta-testers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
