0

I am trying to simulate a simple Login before someone opens my Google Form but for some reason my function for opening dialog box is not firing when I see the form as a normal user, and my function looks as below:

function onFormOpen() {
  var ui = FormApp.getUi();
  var response = ui.prompt('Getting to know you', 'May I know your name?', ui.ButtonSet.YES_NO);
  if (response.getSelectedButton() == ui.Button.YES) {
    Logger.log('The user\'s name is %s.', response.getResponseText());
  } else if (response.getSelectedButton() == ui.Button.NO) {
    Logger.log('The user didn\'t want to provide a name.');
  } else {
    Logger.log('The user clicked the close button in the dialog\'s title bar.');
  }
}

Thou the dialog box shows up when I view the Form from my Google Drive account.

How would I achieve this alternatively so I can pre load some kind of dialog box or something that the user needs to enter some password in order to continue with the rest of the form. Anyone has any idea about this?

Rubén
  • 34,714
  • 9
  • 70
  • 166
pranvera hoti
  • 107
  • 3
  • 15
  • Think the [video given](https://www.bettercloud.com/monitor/the-academy/restrict-access-to-google-forms/) here gives an easier solution. No coding require. Also, you cannot use scripts to modify behavior of the live google form, the script above only works with edit URL of the form. – Jack Brown Apr 06 '17 at 20:52
  • @JackBrown thanx for your reply, I am just wondering why it only works on the Edit Form, when is that useful? Isn't it suppose to work on when a normal user opens it too? – pranvera hoti Apr 06 '17 at 20:54
  • @JackBrown in my case the video does not seem to work for me, as I need to validate the inputs using a checkdigit algorithm, so I need to write some javascript function and check if the input is true or false, so I dont know in this case how do I call that function when input is given by a user in form.... – pranvera hoti Apr 06 '17 at 21:04
  • Answer to why, that is how google designed it. Also, more customization leads to issues with handling responses to the form. [More details here](https://developers.google.com/apps-script/guides/triggers/events#google_forms_events) – Jack Brown Apr 06 '17 at 21:10
  • Form scripts only run on the server side, not the client side. In order to interact with the person completing the form you would have to be able to act on the client side. You can interact client side with the [HTML Service](https://developers.google.com/apps-script/reference/html/) which will require you to create the form via HTML. This can be part of the receiving spreadsheet, or a script saved directly into a drive folder much like a spreadsheet or doc. It si not, however, available in Google Forms. – Karl_S Apr 06 '17 at 21:14
  • @Karl_S I think this is the only way I should go with, do you have any example of that? thnx anyhoe – pranvera hoti Apr 06 '17 at 21:17
  • @Karl_S is it possible that I can create the form pragmatically from the script editor and than manipulate with the inputs somehow? Does this thing work on a person completing the form? thnx – pranvera hoti Apr 06 '17 at 21:36
  • Here is a [sample concept of a form](https://script.google.com/macros/s/AKfycbwFnFFbFqo7637XwSc_eViUODFLZ3wnBo5kvP9VqrTd8ieXdls/exec) I created recently. Everything is written in a Script file saved in the drive. HTML for the form and GAS with client side items for the interaction. All using the HTML Service mentioned above. The final was used in an iFrame on a website. – Karl_S Apr 07 '17 at 12:35
  • Possible duplicate of [How do I add a login to a Google Form for users completing it](http://stackoverflow.com/questions/43266869/how-do-i-add-a-login-to-a-google-form-for-users-completing-it) – Rubén Apr 08 '17 at 17:10

0 Answers0