Help needed sending variables to email / Google Docs form

Jun 15, 2014

Hi all Heroes

OK - so I need to send two simple text variables to an email address or Google Docs form. I have tried both methods without much success. Here is what I have tried:

The 2 variables are : txtName, txtEmail

1. Sending to email (button on slide 2): I have got this one to work, although I'd like the email to send automatically, without the email application opening and the user having to press 'send'.

2. Sending to Google docs: I cannot get this one to work (button on slide 2). Please could someone look at my Java code. Perhaps I'm referencing the form incorrectly.

3.Sending to Google docs by opening Google form in web object (slide 3): this works although I would rather not have this option.I'd prefer the user to enter their name and email within the Storyline course.

The ideal solution is sending an automatic email or the automatic filing in of the Google doc form. Are any of these options possible?

The source file is attached

Thanks,

Lucia

salterslucia@gmail.com

12 Replies
Steve Flowers

Hi Lucia - 

The email method (1) should work but won't work consistently depending on how users have their email client configured. Those, like me, that don't have an email client configured will end up going nowhere with a mailto address.

For method 2, I see what you were trying to do but there's an odd mix of stuff there and ActiveX will only work in IE. For something more cross browser, you'll want something like this. The value in refEmail below can be found by inspecting your form and grabbing the form value. The form uses this to process the pair.

var player=GetPlayer();

var vEmail=player.GetVar("varEmail");

var refEmail="entry.608208641";

var fTarget="https://docs.google.com/a/forms/d/yourformREFERENCE/formResponse";

var postString=fTarget+"?"+refEmail+"="+vEmail+";

var xmlhttp;

if (window.XMLHttpRequest)

{

  xmlhttp=new XMLHttpRequest();

  }

else

{

  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

  }

xmlhttp.open("GET",postString,true);

xmlhttp.send();

Lucia Salters

Thanks Steve - but I still cannot get it right.

The google form has two inputs. Name and Email address.

I am publishing to Dropbox and testing from there.

Here is my button script (from you). It is on the "docs 2" button on slide 2. Where do I add the user name (txtName) into the string?:

var player=GetPlayer();

var vEmail=player.GetVar("txtEmail");
var vName=player.GetVar("txtName");


var refEmail="entry.608208641";

var fTarget="https://docs.google.com/a/forms/d/1-GKv8TKZaMYyQE7qEqp4GK2NIrD_-bwFRIHeg8vyOVc/formResponse";

var postString=fTarget+"?"+refEmail+"="+vEmail+";

var xmlhttp;

if (window.XMLHttpRequest)

{

  xmlhttp=new XMLHttpRequest();

  }

else

{

  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

  }

xmlhttp.open("GET",postString,true);
xmlhttp.send();

Steve Flowers

My script above didn't work very well in some cases. This worked a bit better:

In a trigger at the slide level, when the timeline starts. This loads JQuery into the head of the document:

function add_script(scriptURL,oID) {

     var scriptEl = document.createElement("script");

     var head=document.getElementsByTagName('head')[0];

      scriptEl.type = "text/javascript";      

      scriptEl.src = scriptURL;      

      scriptEl.id=oID;      

      head.appendChild(scriptEl);}

//only want to add these once!

if(document.getElementById('jquery')==null){

add_script("https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js","jquery");

}

In another trigger, this one probably in a button. You'll want to make sure there's enough time for Jquery to load. You might want to setup a loop and check to see if it has loaded before executing. The values in the data set below, such as entry.907772381, are taken from your form field ID's. 

var player=GetPlayer();

var vName=player.GetVar("txtName");

var vEmail=player.GetVar("txtEmail");

var fTarget="https://docs.google.com/forms/d/yourFormKey/formResponse";

function submit_form(){$.ajax({          

url: fTarget,          

type: "POST",          

data: {"entry.907772381" :vName,"entry.602177463":vEmail},          

success: function(data)           {              

//won't return since it's cross domain          

}        

});  

 return false;

}

setTimeout(submit_form(), 2000);

Renee Schuh

I love this conversation and I have a client who wants to do exactly this! She wants to use a text entry and when the learner clicks submit, the text entry answer goes to an email OR a Google document (I realize this is two separate things). As I was looking through this thread, I couldn't get it to work. First, I couldn't get the trigger to perform "on submit go to email." I think it's because I don't use an email application and my browser wanted to open an email application. Right? My questions:

Does a send email trigger submit a text entry or just a notification that the user clicked submit?

Is there a way to have the whole text entry from the learner be submitted to an email? To a Google doc?

Does someone have step-by-step instructions how to do this - as I couldn't get the above to work for me? Do I have to go into the publish file and copy/paste code? Or set up a variable (btw, I don't use variables often which is why I'm wondering if someone has step-by-step instructions!).

Thank you!

Ashley Terwilliger-Pollard

Hi Renee,

The email trigger is a tricky one, and as you mentioned you'll need to have an email client installed.  The email trigger generally just generates an email message but it's up to the user to fill it in, unless you've implemented some additional Javascript as mentioned here - this is not something that I can offer support for, so I'll defer to the community. 

Peter Rich

@Steve,

    I was excited to try this solution out in order to send data directly to a google sheet.  After setting everything up in AS2 and Google Drive and making sure I had no syntax errors, I ran the code and received a 405 error (method) denied.  It may be that Google disallows this type of action where they previously allowed it.  The error I got was:

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://10.10.163.136' is therefore not allowed access. The response had HTTP status code 405.  

a 405 error is listed in the w3c as

The method specified in the Request-Line is not allowed for the resource identified by the Request-URI. The response MUST include an Allow header containing a list of valid methods for the requested resource.

Any ideas of how to get around this limitation?

This discussion is closed. You can start a new discussion or contact Articulate Support.