Google forms onsubmit

How is the default submit button link to associate an onsubmit trigger with another action? Thanks.

For example, with onsubmit,

Logger.log('do something'); 
+8
google-apps-script google-form
source share
5 answers

Not. The Form service does not allow programmatic control over a product. There is an open issue for this general topic in Tracker Issue. Star to "vote" and receive updates.

However, you are not lost. In a spreadsheet that receives your form responses, you can add a script using Installable Trigger to run "On form submit". From there, you can do a lot with the submitted data, including Logging as you want ... but nothing for the form itself.

Triggers

These links explain triggers and events.

+6
source share

Instead of adding a script to the table receiving responses from the form (as in the response of Mogsdad), I added a script that is launched by the "Submit form" button.

Step 1: Create a Google Form First

sample google form

Step 2: Then from the menu, select Tools → Script editor

Form editor menu bar

Step 3: gives your function a name similar to onSubmit()

Script editor

Step 4: Write some code to send an email like this, then click on the “Run” button

 function onSubmit() { MailApp.sendEmail("fred@email.com,alice@email.com", "Subject", "A new application has been submitted.\n\n" + "Here is the link to all Applications:\n" + "https://docs.google.com/spreadsheets/x/1-fdasjhFAKEfdaahfkhsa/", {name:"From Name"}); } 

Step 5: in the script editor menu, click Run or click the Play button on the toolbar to verify your code. (for example, make sure you receive a letter)

Menu bar Run command

Step 6: in the script editor menu, click Resources-> Current Project Triggers

Script Editor menu bar

Step 7: select Event settings From form On form submit

Google App Triggers

Step 8: Then, in the "Form Editor" menu, select Tools → Script Manager and make sure that the script is selected

Script manager

Step 9: try the form. You should receive an email after clicking the submit button.

Google Apps live Form

+6
source share

This is an old answer.

Currently (January 2014) there are two ways for onSubmit. One of them is simply to make the onSubmit () function, which supposedly (it does not work for me ...) allows a limited set of actions only with the permission of the current subordinate user. For example, you cannot access his sent letter or change the basic form for the next sending.

Then there is a trigger for sending, which you can add and attach to any function and do whatever you want, under your own permissions. looks like a screenshot of the trigger adding to the answer above, except that its first column shows the methods in your script forms, the next column reads: From-Form and in the third column you select: On Submit.

Typically, your method will receive an e event, the value of e.values ​​matches the values ​​stored in the spreadsheet. So,

function formSubmitted (e) {...

+3
source share

It seems that there are two applications that invoke code: (1) the form and (2) the spreadsheet associated with the form responses.

(1) There is not much that can be made into a program from a form, since an event is not sent to functions, as noted above by Mogsdad and John. For example, you can send an e-mail “On form submit” or “On open”, but without an event object it is not even possible to write a number or lines or nothing about a document or presentation.

(2) However, if the spreadsheet is associated with form responses, then the trigger can be installed in the spreadsheet where the user has access to the event and, therefore, the row, column and other data.

From the related answer, google table:

  • Step 1: Tools> Script editor
  • Step 2: write some code, for example:

Code.gs:

 function onSpreadsheetSubmit(e) { var row = e.range.getRow(); MailApp.sendEmail("me@example.com", "Your subject, rows: "+ row, "A new application has been submitted on row: "+ row, {name:"From your friendly spreadsheet"}); } 
  • Step 3: Run> Run -> onSpreadsheetSubmit (or |> icon)
    • The event probably does not have a real line, because the test is not related to the actual dispatch.
  • Step 4: you will be asked to select a user and authenticate
  • Step 5: Editing> Current project triggers (or a clock-like icon)
  • Step 6. Add a new trigger
  • Step 7: onSpreadsheetSubmit | From the table | By submit form
  • Step 8: Authentication and Retention (or Reverse)
  • Step 9: Validation by Waiting (or Executing) the Presentation of the Real Form
  • Step 10: check your email address

For more information: https://developers.google.com/apps-script/guides/triggers/events#google_sheets_events

+1
source share

JohnB HOWTO above excellent. Update (November 2017):

  • Step 2: "Script Editor ..." is located in the vertical "..." hamburger menu in the upper right corner of the form
  • Step 6: “Project triggers” are in the form (resembling a clock) (the second icon is displayed above).
  • Step 7: Click "Add New Trigger", ignore the warning "no myFunctions".
  • Step 8: it seems it does not exist, it may not be needed, it works for me without.

Many of the above steps require confirmation / acceptance by the owner of the form.

0
source share

All Articles