Search code examples
google-apps-scriptgoogle-sheetsgoogle-forms

Displaying a Google form on sheets


I am creating a form for users to input information on a Google spreadsheet. They will access the spreadsheet and then click on an image that is linked to a script. When the image is clicked, I want a form to appear. Then I want the input from the form to be accessible in the script.

I am able to create a form but the form does not appear on the sheet. Here is the code thus far for the GS script

function startForm() {
   var form = FormApp.create('myForm');
  var item = form.addCheckboxItem();
  item.setTitle('What would you like to do?');
  item.setChoices([
        item.createChoice('Budget Inquiry'),
        item.createChoice('Add Purchase')
  ]);
  var choices = item.getChoices();
  // then I can respond to the user's choice
}

I would like this simple form to just appear on the google sheet. Any input would be appreciated.


Solution

  • Instead of creating you own form with script, just go to the insert menu of your spreadsheet and select form. Enter you question and your two choices. Close the form. You will see a form response sheet created in your spreadsheet. Also, a menu item Form will appear on your menu. Then go to the script editor and from the menu select Resources. Select Current Project Triggers and set a new trigger for onFormSubmit. You can then enter a function onFormSubmit to do whatever you want done when the form is submitted getting data from the form response sheet. There is plenty of documentation you can Google.