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

我的未来我决定 提交于 2019-12-20 07:20:28

问题


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?


回答1:


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:

  • How to Customize & Validate Google Docs Form (an easier way?)
  • Custom multi-step Google forms

On https://webapps.stackexchange.com

  • Answer to Apply custom CSS styles to Google Forms


来源:https://stackoverflow.com/questions/43266869/how-do-i-add-a-login-to-a-google-form-for-users-completing-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!