Day 14 – Posting Data to Google Spreadsheet

Goal: Be able to post data from a Kynetx app to a Google spreadsheet using KRL

Pre KRL code writing step:

Create a Google spreadsheet with text fields of the data you want to submit to the form.

Find form tags when viewing source of live form

Form HTML from my Google form live source

<form action="https://spreadsheets.google.com/formResponse?formkey=dHE2YkUwOEFyR1d2bmxFUE9NRnRxRVE6MQ&amp;ifq" method="post" id="ss-form" name="ss-form">
  <br>
  <div class="errorbox-good">
    <div class="ss-item ss-text">
      <div class="ss-form-entry">
        <label class="ss-q-title" for="entry_0">url</label> <input type="text" name="entry.0.single" value="" class="ss-q-short" id="entry_0">
      </div>
    </div>
  </div><br>
  <div class="errorbox-good">
    <div class="ss-item ss-text">
      <div class="ss-form-entry">
        <label class="ss-q-title" for="entry_1">rule version</label> <input type="text" name="entry.1.single" value="" class="ss-q-short" id="entry_1">
      </div>
    </div>
  </div><br>
  <div class="errorbox-good">
    <div class="ss-item ss-text">
      <div class="ss-form-entry">
        <label class="ss-q-title" for="entry_2">IP</label> <input type="text" name="entry.2.single" value="" class="ss-q-short" id="entry_2">
      </div>
    </div>
  </div><br>
  <input type="hidden" name="pageNumber" value="0"> <input type="hidden" name="backupCache" value="">
  <div class="ss-item ss-navigate">
    <div class="ss-form-entry">
      <input type="submit" name="submit" value="Submit">
    </div>
  </div>
</form>
  • 1 form action URL is needed to post to the form
  • 06 input name is needed to post to that field
  • 13 oh look! Another input name. This one is ‘entry.1.single’
  • 20 aaaand another input name
  • 24 hidden input needed
  • 27 submit input needed
ruleset a60x498 {
  meta {
    name "post-to-google-spreadsheet"
    description <<
      post-to-google-spreadsheet
    >>
    author "Mike Grace"
    logging on
  }

  rule example_post_to_google_spreadsheet {
    select when pageview ".*"
    pre {
      url = page:url("domain");
      ruleVersion = page:env("rule_version");
      ip = page:env("ip");
      stuff =<<
        url: #{url}<br>
        rule version: #{ruleVersion}<br>
        ip: #{ip}
      >>;
    }
    {
      notify("Stuff",stuff) with sticky = true;
      http:post("https://spreadsheets.google.com/formResponse?formkey=dHE2YkUwOEFyR1d2bmxFUE9NRnRxRVE6MQ&amp;ifq")
        with params = {"entry.0.single":url, "entry.1.single":ruleVersion, "entry.2.single":ip, "submit":"Submit", "pageNumber":"0", "backupCache":""};
    }
  }
}
  • 14 returns domain app was run on
  • 15 returns dev or prod for development or production version
  • 16 public IP address of user
  • 17-21 awesome here doc
  • 25 http:post action - form action URL goes as the post URL
  • 26 params of all the names of the input fields with the values to post to those fields

App run on example.com with bookmarklet

Google spreadsheet updates live about 2 seconds later

  • you can use different form input types as long as the name of the input matches what you are trying to post to
  • you can see the response of the http:post action in the logging of the event response if you have logging turned on
  • posting to a google spreadsheet in KRL is easy and hopefully this post helps others see just how easy it is
  • there has been some rumors that real integration with google docs is going to be in the works in the future… ssssshhhhhhh! you didn’t here it from me.
  • don’t be evil – Kynetx reserves the right to review app code for malicious behavior and reserves the right to turn off your app if you are being evil
  • be awesome!
  • have fun
  • smile
  • post comments

Get the bookmarklet to try it out yourself!

Gratuitous day 14 Grace face

About these ads
This entry was posted in Kynetx. Bookmark the permalink.

One Response to Day 14 – Posting Data to Google Spreadsheet

  1. Jibu says:

    Hello
    I am using this form for product details, how can i pass the product name as hidden field to know which product user selected ?
    Do u have an idea ?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s