简体   繁体   中英

How do I add a login to a Google Form for users completing it

I have been reading and watching many tutorials online but I could not find something that I can initially load some kind of dialog box or login page with a single input text so then I can process that using apps script.

onFormOpen() is not triggered on the user who completes the form.

On my onSubmitForm() function I have the following code:

function onFormSubmit(e){
  var formResponses = FormApp.getActiveForm().getResponses();
  var formResponse = formResponses[formResponses.length-1];
  var itemResponses = formResponse.getItemResponses();
  for (var j = 0; j < itemResponses.length; j++) {
    var itemResponse = itemResponses[j];
    Logger.log('Last response to the question "%s" was "%s"',
               itemResponse.getItem().getTitle(),
               itemResponse.getResponse())
  }
}

Is there any way I can prevent from here the form being submitted with some kind of logic condition, for ex: execute the form submission only if certain field matches some condition?

Is there any way I can prevent from here the form being submitted with some kind of logic condition, for ex: execute the form submission only if certain field matches some condition?

You could use form rules :

You can create rules that people have to follow when they fill out your form. For example, if you ask for email addresses, you can make sure that people can only submit properly formatted email addresses.

Regarding onFormOpen() there isn't a built-in trigger named that way. You could use that as name for an on open installable trigger but it only runs when the form editor is opened, not when the form view is opened.

Regarding adding a custom logging, if you use a G Suite account you could limit the access to users from the same domain as your account but you could not limit access further this.

A hacky alternative is to take the source code from the form view and "adapt" it to be served by a Google Apps Script or host it on your own web server. This implies that you will inject your custom form rule/data validation. The easier way is by using the old Google Forms and copy/paste the source code of the form but it's possible to use UrlFetch.

Another alternative is to use the HtmlService Service from Google Apps Script to create and serve your form which practically will give you complete control of your form behavior. See Forms - HTML Service: Communicate with Server Functions

Related:

On https://webapps.stackexchange.com

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM