Steven Mileham – General Geekery

June 12, 2012

Send Google Form data as an Email on submission

Filed under: Technology — Tags: , , , — smileham @ 2:47 pm

Google Docs includes a great tool for customer feedback, survey’s and request forms in the Google Forms functionality. When data is submitted into the form, a new row of results is added to the corresponding Google Spreadsheet.

The default functionality of Google Forms allows for aggregated data and statistical data. My requirement was to be emailed the results of each submission to the form as they happened.

By adding the following code to your Google Spreadsheet, you can send each submission to an email.

  1. function emailFormSubmission() {
  2.   var theFormSheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  3.  
  4.   // Update these to reflect your requirements
  5.   var theEmail = "example@example.com";
  6.   var theSubject = "Form Responses";
  7.  
  8.   var theQuestions = theFormSheet.getRange(1, 1, 1,theFormSheet.getLastColumn()).getValues();
  9.   var theForm = theFormSheet.getRange(theFormSheet.getLastRow(), 1, 1,theFormSheet.getLastColumn()).getValues();
  10.   var theBody = ‘<table id="answers"><tr><th>Question</th><th>Answer</th></tr>’;
  11.  
  12.   for (var i = 0; i< theForm[0].length; i++)
  13.   {
  14.     if (theForm[0][i]!="")
  15.     {
  16.       theBody += ‘<tr><td>’+theQuestions[0][i]+"</td><td>"+theForm[0][i]+"</td></tr>";
  17.     }
  18.   }
  19.   theBody += ‘</table>’;
  20.  
  21.   MailApp.sendEmail(theEmail, theSubject, "",{htmlBody: theBody});
  22. }

Once you’ve added this code to your spreadsheet, just set the trigger to run on form submission and each time a new form is submitted an email will be sent with the contents of the form. This method maintains the order of the questions asked, and only shows the questions which have been answered.

Here is a link to an example Google Spreadsheet which includes the code/form.
Send Google Form data as an Email on submission

Hope it helps, feel free to drop a comment with any suggestions/questions.

July 19, 2010

Tumble weed

Filed under: Photography,Technology — smileham @ 9:49 am
Tumblr

I recently stumbled upon tumblr. I’ve known of it’s existence for ages, but couldn’t really find a use for it. I’ve now set it up as a “photo blog” with the aim of posting a photo a day from my iPhone to it.

If you want to check it out, head to;

http://tumblr.smileham.co.uk

October 23, 2009

Google Analytics – Tracking page categories

Filed under: Technology — Tags: , , — smileham @ 2:30 pm

I’ve recently been looking at how I can use Google Analytics to track website usage of content based on the category it has been assigned.  We are using META tags in the page headings to store the category name and title of the content.

Google have just rolled out a bunch of excessively handy features allowing custom variables in their most recent update to the analytics package, unfortunetly my Analytics account hasn’t yet been updated to include them.  As a fall back I’ve used the Event Tracking functionality instead.

At the bottom of each page which I want to track the category of, added the following code;

  1.  
  2. <script type="text/javascript">
  3.   var pageTracker = _gat._getTracker("<%= googleAnalyticsId %>");
  4.  
  5.   function getMeta(name) {
  6.     var metas = document.getElementsByTagName(‘META’);
  7.     for (var i = 0; i < metas.length; i++){
  8.       if (metas[i].getAttribute(‘NAME’) == name){
  9.         return metas[i].getAttribute(‘CONTENT’);
  10.       }
  11.     }
  12.     return "null";
  13.   }
  14.  
  15.   try {
  16.     var cat = getMeta("CATEGORY");
  17.     var title = getMeta("ARTICLE_NAME");
  18.  
  19.     if(cat != "null" &amp;&amp; title != "null"){
  20.       pageTracker._trackEvent(‘Category’,cat,title);
  21.     }
  22.   }catch(ex){
  23.     /* do nothing */
  24.   }
  25.   pageTracker._trackPageview();
  26. </script>
  27.  

Using this codes means that I can put these meta tags into the headings of any page;

  1.  
  2. <meta name="CATEGORY" content="Analytics" />
  3. <meta name="ARTICLE_NAME" content="Custom Variables" />
  4.  

And Google Analytics will track the my each of my articles based on the category they have been tagged with.

October 21, 2009

Spring frustrations

Filed under: Technology — smileham @ 2:54 pm

I’m currently developing ten tonne of portlets using the Spring Portlet MVC framework.  It’s been a frustrating but rewarding experience.  I’ve been struggling with general documentation and examples for a while, and I wanted to make a quick post about a problem I’ve been having.  Mainly because I found lots of people with similar issues, but no help at a resolution.

I’ve been using the AbstractWizardFormController, and over-riding the

  1.  
  2. public ModelAndView showForm(RenderRequest request, RenderResponse response, BindException errors) throws Exception
  3.  

method to display my view and the
protected Object formBackingObject(PortletRequest request) throws Exception
method to populate my command bean.

My XML looked like this;

  1.  
  2. <bean id="menuSpotlightController" class="uk.co.smileham.cms.controller.edit.SpotlightController">
  3.         <property name="viewName" value="spotlightMenu" />
  4.         <property name="commandName" value="preferenceCommand" />
  5.         <property name="commandClass" value="uk.co.smileham.cms.model.PreferenceCommand" />
  6. </bean>
  7.  

This all seemed fine to me, however whenever I then tried to use the porlet I’d have a huge exception that went something along the lines of;

  1.  
  2. 2009-10-21 14:04:28,765 ERROR [http-8080-Processor19] org.springframework.web.servlet.tags.form.SelectTag – Neither BindingResult nor plain target object for bean name ‘preferenceCommand’ available as request attribute
  3. java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name ‘preferenceCommand’ available as request attribute
  4.         at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:141)
  5.         at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:172)
  6.         at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:192)
  7.         at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:158)
  8.         at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:121)
  9.         at org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:379)
  10.         at org.springframework.web.servlet.tags.form.SelectTag.writeTagContent(SelectTag.java:198)
  11.         at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:90)
  12.         at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:77)
  13.         at org.apache.jsp.WEB_002dINF.jsp.spotlightMenu_jsp._jspService(spotlightMenu_jsp.java:658)
  14.         at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
  15.         at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
  16.         at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
  17.         at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
  18.         at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
  19.         at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
  20.  

After much frustration I discovered that the problem was that the “preferenceCommand” was being set in the model, but then being overridden by a new model in my showForm() method.

The solution was to read the documentation (funny that) and eventually found that when using the AbstractFormController you should not directly create a new ModelAndView object to return but instead get the current model from the “BindException errors” variable that has been passed in and then “return super.showForm(request, errors, viewName);”

So my final showForm method went from;

  1.  
  2. public ModelAndView showForm(RenderRequest request, RenderResponse response, BindException errors) throws Exception {
  3.                 ModelAndView mav = new ModelAndView(viewName);         
  4.                 return mav;
  5.         }
  6.  

to

  1.  
  2. public ModelAndView showForm(RenderRequest request, RenderResponse response, BindException errors) throws Exception {
  3.                 Map<String,Object> model = errors.getModel();
  4.                 return super.showForm(request, errors, viewName);
  5.         }
  6.  

That may all seem like giberish, but hopefully it’ll mean that someone else seeing the same problem might figure out what’s going on sooner! (That and I shouldn’t fall into this problem again any time soon now.)

October 20, 2009

Redlaser – nerdgasm

Filed under: Technology — Tags: — smileham @ 1:24 pm
RedLaser logo

RedLaser

Over the weekend I was sitting in a cafe with a friend of mine who works at a supermarket.  He mentioned that he’d heard of a program on the iPhone which could read barcodes, RedLaser.  I grabbed a copy, and we played around for a moment scanning the shopping we’d just bought.

Then sitting at home this morning, my eyes wandered to my DVD collection, and cogs began to whirr.  A few moments later and I started the task of scanning each DVD, with the aim of e-mailing the list of results to myself, thus cataloguing my collection.  Next I start on the CDs and books.  So yeah, I had a nerdgasm, but only a little one.

March 12, 2009

Random Weather

Filed under: Technology — Tags: , — smileham @ 11:56 am

Similar to the foliagometer a while ago, I stumbled across another “fun” feature on a website today.

The random weather generator of devthought.com.  Worth checking out for a bit of inspiration.

Built using MooTools rather than jQuery, but I wouldn’t hold that against it :)

Devthought — JavaScript, MooTools, PHP, Symfony, WordPress and all the stuff you love.

February 26, 2009

The future of Google Chrome

Filed under: Technology — Tags: , , , , — smileham @ 6:14 pm

Google as a company just seem to get it, by introducing (yet) another browser into the wild, they began another round of the browser wars. Kicking off a flurry of innovation, which browser manages to render the acid tests? Who can perform the most javascript calls per milli-second? etc.

All Google seems to care about is that this innovation continues, so that they can build web applications to run on these platforms.

This interview is really worth a read to see the direction of Google and the Chrome browser.

Interview: what’s next for Google Chrome

Always the Google fan boy!

February 23, 2009

JQuery 1.3.2 Released

Filed under: Technology — Tags: , , — smileham @ 2:51 pm

I am definitely a huge fan of jQuery.  Every release seems to astound and amaze in it’s sheer brilliance and genius.  The new ad spinner on the home page is written in jQuery, as well as the small bit of functionality on the Photography page.

Anyway, go and check out the newest release, mostly a maintenance update, it still has a few new features too! I shall certainly be using jQuery in all future developments!

jQuery 1.3.2

February 20, 2009

Ajaxian » The Campaign To End IE6

Filed under: Technology — smileham @ 11:30 am

no-ie6-logoWho would have believed that it was the Norwegians that would lead the charge in the revolution?

IE6 is the bane of the web developer.  With the (hopefully) imminent release of Internet Explorer 8 (with its huge list of “incompatible” websites) the world will be one step closer to a standards compliant web, and developers will be able to take a step back from the brink of madness.

Several websites in Norway have kicked the pebble down the hill which I hope will cause an avalanche.  They have stopped developing for this hideous browser and provide a nice big warning to anyone using the out dated monster to upgrade to a newer browser.

Ajaxian » The Campaign To End IE6.

Viva la resistance!!

February 13, 2009

Your Software Made Me Cry: How to Select an Open-Source Java Portal for your Enterprise

Filed under: Technology — Tags: , — smileham @ 5:00 pm

The sad hideous truth of Liferay…

I still love Liferay, but this may save some people a bit of heart break!  I went through almost exactly the same journey in choosing Liferay for a new large scale website.

At first it seems to offer everything you ever wanted in a portal system, even more so (including making the coffee), but once you start to look beneath the hood, things become a little murkier.  It was after a shambolic training course that I fell out of love with Liferay, but after looking through a few alternatives, it became the best contender again.

It’s all about managing expectations…

Your Software Made Me Cry: How to Select an Open-Source Java Portal for your Enterprise.

Older Posts »

Powered by WordPress