Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Forms onsubmit

How does one reference the default 'Submit' Forms button to link the 'onsubmit' trigger with another action? Thank you.

For example, with onsubmit,

Logger.log('do something');
like image 380
user2012403 Avatar asked Mar 28 '13 15:03

user2012403


3 Answers

Instead of adding a script to the Spreadsheet receiving responses from the Form (as in Mogsdad's answer), I added a script which gets triggered by the Form's Submit button.

Step 1: first create a Google Form

sample Google Form

Step 2: Then from the menu, click Tools->Script editor

Form editor menu bar

Step 3: give your function a name like onSubmit()

Script editor

Step 4: Write some code to send an email like this, then test by click Run button

function onSubmit() {
  MailApp.sendEmail("[email protected],[email protected]",
                    "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's menu, click Run, or click the Play button on the toolbar to test your code (e.g. make sure you get the email)

Menu bar Run command

Step 6: in the Script Editor's menu, click Resources-> Current project's triggers

Script Editor menu bar

Step 7: select the settings Events From form On form submit

Google App Triggers

Step 8: Then from the Form Editor's menu, click Tools->Script manager and make sure your script is selected

Script manager

Step 9: try the form. You should get an email after clicking the form's submit button.

Google Apps live Form

like image 63
JohnB Avatar answered Sep 19 '22 15:09

JohnB


One doesn't. The Form Service does not allow any programmatic control over the product. There is an open issue on the Issue Tracker for this general topic. Star it to "vote", and receive updates.

However, you're not lost. In the spreadsheet receiving your form responses, you can add a script with an Installable Trigger to fire "On form submit". From there, you can do many things to the submitted data, including Logging as you wish... but nothing to the Form itself.

Triggers

These references explain triggers and events.

  • Using Container-Specific Installable Triggers
  • Understanding Events
like image 32
Mogsdad Avatar answered Sep 20 '22 15:09

Mogsdad


This is an old answer.

Currently (Jan 2014) there are two ways for onSubmit. One is simply to make a function onSubmit() which supposedly (it doesn't work for me...) allows a limited set of actions under the permission of the current submitting user only. You cannot access his submitted email, for example, or modify the underlying form for next submit.

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

Typically your method will receive an event e , who's e.values are the same as the values saved in the spreadsheet. So

function formSubmitted(e){ ...

like image 37
pashute Avatar answered Sep 20 '22 15:09

pashute