Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate a pre-filled form URL for Google Form

I'm looking for a programmatic way to automate the generation of pre-filled URLs for google forms.

In a recent update, Google introduced a new Forms product to Google Docs. If you open the tools menu in a spreadsheet, you'll see some new options.

Tools menu with Legacy Form

In the new Form Responses menu, one option is "Get pre-filled URL". This opens up a dialog containing a version of your form that you can fill out, and when you submit it, you receive a URL that can be used to open a Live Form with the data you pre-filled ready and waiting for you. The URL looks something like this...

https://docs.google.com/forms/d/--Form-ID--/viewform?entry.1094330118=Something&[email protected]&entry.540962741&entry.787941281&entry.1873343651

The questions from the form have a fixed identity, e.g. entry.1094330118. They may be pre-filled with a value (entry.1094330118=Something) or blank (entry.7879412).

In apps-script, I'd like to generate these pre-filled URLs for users of my form, so I can provide them for updates. My users are not members of an Apps Domain, so I don't have the option of embedding an Edit your response link.

If I can get the information about the form, I will be able to piece together the URL. While I can go through the UI to create one URL, and dissect it to get the info for that form, I want a solution that will work with arbitrary forms.

  1. How can I programmatically determine the question IDs?
  2. With the new Forms product, is the form available to me through any apps-script APIs? (I know about getFormURL() - that's not what I mean.)
  3. Armed with a question ID, can I get more information about the question? (Question text, type, etc.)
like image 811
Mogsdad Avatar asked Feb 02 '13 03:02

Mogsdad


People also ask

Can you make a custom URL for a Google Form?

Go to the Publish tab in the Form Builder. Click the edit (pencil) icon next to your form's Link to Share URL. Type in your desired URL slug. Click the Apply button.

What does prefilled link mean in Google Forms?

Google Forms has a solution for automatically filling in a free response question. A pre-filled link pre slots some of the answers when the user clicks on the link to the Google Form. Look for the 3 dots menu in the upper right and choose “Get pre-filled link.” This will open a preview of the Google Form.

Can you autofill Google Forms?

As a Google Form editor you can get a pre-filled URL (complete with entry values) by choosing the 'Get pre-filled link' option at the top right of the page, after clicking the three dots. This will open the form in a new tab. The Submit (or Next) button will be replaced with a 'Get link' button.


2 Answers

I required something similar for users to go and edit their response, take a look here: http://productforums.google.com/forum/#!topic/docs/LSKKCR3VHC8

Copy / paste code below:

function assignEditUrls() {
var form = FormApp.openById('1MonO-uooYhARHsr0xxxxxxxxxxxxxxxxxxxxx');
//enter form ID here

  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Form Responses');

    //Change the sheet name as appropriate
  var data = sheet.getDataRange().getValues();
  var urlCol = 4; // column number where URL's should be populated; A = 1, B = 2 etc
  var responses = form.getResponses();
  var timestamps = [], urls = [], resultUrls = [];

  for (var i = 0; i < responses.length; i++) {
    timestamps.push(responses[i].getTimestamp().setMilliseconds(0));
    urls.push(responses[i].getEditResponseUrl());
  }
  for (var j = 1; j < data.length; j++) {

    resultUrls.push([data[j][0]?urls[timestamps.indexOf(data[j][0].setMilliseconds(0))]:'']);
  }
  sheet.getRange(2, urlCol, resultUrls.length).setValues(resultUrls);  
}
like image 76
MPiets Avatar answered Sep 20 '22 02:09

MPiets


This is not possible right now but this request is being tracked on the Issue Tracker here. Please add your use cases there and watch it for updates.

like image 35
Arun Nagarajan Avatar answered Sep 23 '22 02:09

Arun Nagarajan