How does google know which onsubmit trigger to execute when a form is submitted if you have multiple forms sending responses to a single spreadsheet

user2284680

I need clarification from someone.

I understand that multiple forms can send their responses to a single spreadsheet in the new Google Sheets.

So I created two Google forms and had them both send their responses to a new Google spreadsheet. I then created two scripts in the spreadsheet (not in the forms). Each script is set to trigger when a form is submitted. Here are the two simple scripts.

function form2() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form Responses 1");
  sheet.getRange(sheet.getLastRow(),3).setValue("This is for test 2");
}

function form1() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form Responses 2");
  sheet.getRange(sheet.getLastRow(),3).setValue("This is for test 1");
}

Somehow, Google is running the correct script for the appropriate form! How can that be? That is, form1() is automatically triggered when someone submits form1 and form2() is automatically triggered when someone submits form2.

So my question is, "How does Google know which script to run when a form is submitted?".

Thanks. I want to send all my form data to one spreadsheet if possible, but I don't want to set something up that will be unreliable.

-jay


Thanks wchiquito for your answer. I think that I figured this out with your help. Here is what I think is going on. If someone can confirm or disprove my conclusions it would be a big help to me.

There are two ways of creating a form in Google Apps.

  • Create a Form Directly.
  • Create a spreadsheet first and then create the form by selecting "Form" and then "Create Form" from within the menu bar of the spreadsheet.

But no matter how you create your form, you will end up having two files. One will be for the form and one will be for the spreadsheet which receives the data from the form. If you put the script in the form and in a spreadsheet, both will run when the form is submitted. The difference is that any script in the form will be limited in permissions. That is, any script in the form will not be able to access the spreadsheet where-as the script in the spreadsheet will have all of the permissions that you have (as long as the trigger is set under your account).

Now...

The new Sheets in Google Drive now has the ability to receive responses from more than one form while the old sheets in Google Drive only had the ability to receive one form responses. This eventually lead to my confusion and the answer from wchiquito is correct. It appears that the receiving spreadsheet will run as many onsubmit scripts as you like, but whether it is one or more than one, they will all run on all form data being received by the spreadsheet. That is, when the receiving spreadsheet receives form data from any form, ALL onsubmit scripts within the spreadsheet will be executed.

wchiquito

Both scripts should be executed, perhaps by using literal strings, the change is not visible.

Try running with the following changes:

function form2(e) {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Form Responses 1');
  sheet.getRange(sheet.getLastRow(), 3).setValue(e.values);
}

function form1(e) {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Form Responses 2');
  sheet.getRange(sheet.getLastRow(), 3).setValue(e.values);
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How does google know which onsubmit trigger to execute when a form is submitted if you have multiple forms sending responses to a single spreadsheet

From Dev

How to submit single form via AJAX when you have multiple forms from PHP loop

From Dev

Know which Form is submitted

From Dev

Know which Form is submitted

From Dev

Form onSubmit function not firing when form submitted

From Dev

How to let ngForm know that the form it is nested in have been submitted

From Dev

jQuery submits only one form when multiple forms are submitted

From Dev

Populate a Google Form responses from a Google Spreadsheet

From Dev

How to access Spreadsheet from a Google Forms submit trigger function

From Dev

How to validiate form onsubmit when form is submitted via a link instead of a button

From Dev

How to make phpmailer code only execute when form is filled and submitted?

From Dev

Simple PHP contact form not sending when submitted

From Dev

Why does form get submitted after onsubmit return undefined?

From Dev

How to create multiple forms for Single Model and all forms must be submitted by one submit button?

From Dev

Execute $.ajax when HTML form submitted

From Dev

Execute $.ajax when HTML form submitted

From Dev

How is it possible to find the current row index when a google form is submitted/re-submitted? Google apps script

From Dev

Google Docs API - Spreadsheets which are Form Responses

From Dev

How does Express know which Router path to use when multiple paths match?

From Dev

Edit Form Responses as soon as it is submitted

From Dev

How to check which button have been submitted

From Dev

How to check which button have been submitted

From Dev

How does django know which migrations have been run?

From Dev

Rails: How to check which form in a view was submitted

From Dev

When sending a push notification to multiple Android devices how can I detect which specific device(s) have had the app uninstalled?

From Dev

How to know where an app starts when you have no main()?

From Dev

Google Spreadsheet - How to avoid sending email duplicates?

From Dev

Google Spreadsheet doesn't start at top when responses are cleared

From Dev

Why does form still submit when you have javascript disabled?

Related Related

  1. 1

    How does google know which onsubmit trigger to execute when a form is submitted if you have multiple forms sending responses to a single spreadsheet

  2. 2

    How to submit single form via AJAX when you have multiple forms from PHP loop

  3. 3

    Know which Form is submitted

  4. 4

    Know which Form is submitted

  5. 5

    Form onSubmit function not firing when form submitted

  6. 6

    How to let ngForm know that the form it is nested in have been submitted

  7. 7

    jQuery submits only one form when multiple forms are submitted

  8. 8

    Populate a Google Form responses from a Google Spreadsheet

  9. 9

    How to access Spreadsheet from a Google Forms submit trigger function

  10. 10

    How to validiate form onsubmit when form is submitted via a link instead of a button

  11. 11

    How to make phpmailer code only execute when form is filled and submitted?

  12. 12

    Simple PHP contact form not sending when submitted

  13. 13

    Why does form get submitted after onsubmit return undefined?

  14. 14

    How to create multiple forms for Single Model and all forms must be submitted by one submit button?

  15. 15

    Execute $.ajax when HTML form submitted

  16. 16

    Execute $.ajax when HTML form submitted

  17. 17

    How is it possible to find the current row index when a google form is submitted/re-submitted? Google apps script

  18. 18

    Google Docs API - Spreadsheets which are Form Responses

  19. 19

    How does Express know which Router path to use when multiple paths match?

  20. 20

    Edit Form Responses as soon as it is submitted

  21. 21

    How to check which button have been submitted

  22. 22

    How to check which button have been submitted

  23. 23

    How does django know which migrations have been run?

  24. 24

    Rails: How to check which form in a view was submitted

  25. 25

    When sending a push notification to multiple Android devices how can I detect which specific device(s) have had the app uninstalled?

  26. 26

    How to know where an app starts when you have no main()?

  27. 27

    Google Spreadsheet - How to avoid sending email duplicates?

  28. 28

    Google Spreadsheet doesn't start at top when responses are cleared

  29. 29

    Why does form still submit when you have javascript disabled?

HotTag

Archive