Elliott Shafii
Elliott Shafii

Reputation: 111

Posting data to HtmlService from separate form

I recently noticed that you cannot embed a HtmlService app in a non Google Sites site.

What I was wanting to do is have a chrome extension which was a simple form to capture feedback from users. The form would be powered by HtmlService and the data from the form captured in a spreadsheet. I know, you could do this with Google Forms, but the design and layout are not good enough to encourage users to complete the form as regularly as we wish.

As I can't embed the HtmlService apps as an iframe in the popup.html in my extension I'm wondering if I can simple have a form with a post action back to the HtmlService app.

Is this possible to have the post go back to the app? If so what would the post look like and what would the function look like to capture this data?

Upvotes: 1

Views: 200

Answers (1)

Greg
Greg

Reputation: 737

I have done this a couple of ways, but I ended up doing a simple local html page with a form:

<form action="yourScriptURL" method="get">
  <input type="text" name="firstName" />
  <input type="text" name="lastName" />
</form>

And then in your apps script:

function doGet(GETVARS){

  var firstName = GETVARS.parameters.firstName;
  var lastName = GETVARS.parameters.lastName;

  Logger.log(firstName + " " + lastName);

  //return Whatever you want here, HtmlService, UiApp, ContentService, etc
}

If you wanted, you can set the correct SCP info in your Chrome Extension/App and use JSONP to do this via AJAX. Works pretty well actually - you just need to plan out how the script is authorized, how the user is authenticated (or not) to use it, etc. It's really not as bad as it sounds.

Upvotes: 1

Related Questions