Hidden field in a Google Form

I assume you're only interested in ways to programmatically assign a unique ID before the user fills out your form.

No, Google Forms still has no direct support for hidden fields such as you have in HTML Forms. Your only option appears to be the custom styling route, which you're already aware of.

Here are two promising ideas that just don't work...

  1. Pre-fill a deleted question. If you delete a question from a form, it remains in the response spread sheet - unfortunately Forms suppresses values for deleted questions that are presented in pre-filled URLs, otherwise you'd be able to trick your Unique ID into the submission that way. (I thought this might be a clever work-around, but was disappointed that it didn't work.)

  2. Pre-fill a question on a skipped page1. You can set up a question on a second page that the live form will skip over, and you can also generate a pre-filled URL for that question. So far, so good - but if the user doesn't actually navigate to that page, the pre-filled response is not submitted.


1Thanks to @AdamL, who posited this idea during a previous discussion on this topic in the old forum.


You can't do this directly by Google Forms but you can work around:

  1. Create the google form containing the hidden field.
  2. Create a Google Wep App (https://developers.google.com/apps-script/guides/web)
  3. Insert the following code into the default Code.gs file. (This basically opens an index.html template.)

    doGet(e) { return HtmlService.createTemplateFromFile('index').evaluate(); }

  4. Create a new index.html file with the source code of your form.

  5. Make the input field hidden by adding style="display:none" to its enclosing <div>
  6. Insert any template information into the <input value=""> field using <?= your_gscript_code() ?>
  7. Publish the web app (Publish/Deploy web app...) and you're done. Now you have a link to a form which has the desired field hidden and pre-filled with your hidden value.

With this solution you can apply any custom style and even get rid of other unnecessary html elements while keeping the form hosted by Google.


I think I've found a solution to your problem. A script on the sheet that your form data is going to can be triggered on form submit. You can then copy and increment a "range" for each row submitted.

*edit, sample code was requested. In order for this code to work you need to "install a trigger" using the resources menu on your google app script, and use "from spreadsheet" "on form submit". I've boiled what I'm doing down to the following snippet.

function myFormUpdates(e) {
  var spreadsheet = SpreadsheetApp.getActive()
  //select the sheet you're form is going to post data to
  var sheet = spreadsheet.setActiveSheet(spreadsheet.getSheets()[1])
  //select the last row and a unused column
  var cell = sheet.getRange(sheet.getLastRow(), 3)
  //set data
  cell.setValue('Data')
}