1

I'm looking for a way to 'pre fill' a google form with specific data from google apps . As you may know, when the user login to the form, it retrieves it's user name, so how can i put the other known fields (email, phone, department) into google form?

5
  • You can't pre-fill an already loaded form. You can pre-fill a form, then open the form pre-filled, but you can't dynamically change input values after the form is loaded. So, what you're asking for isn't "pre-fill" I don't think. There would need to be another step in between getting the user email and opening the form with the correct information. So, it would be a multi-step process. That's your only option. For example, constructing a pre-filled URL with Apps Script, emailing the pre-filled URL in a link to the user, then the user clicks on the link in the email to open the pre-filled
    – Alan Wells
    Commented Oct 27, 2015 at 18:58
  • @SandyGood Thanks Sandy, I need only to show these fields (the user won't change them)
    – JinaneK
    Commented Oct 27, 2015 at 19:17
  • @SandyGood solid answer ! I had same issue before and built a form from scratch. It's kinda long but it will give you more flexibility
    – niwox
    Commented Oct 27, 2015 at 19:19
  • I'm willing to learn & will be patient in applying @niwox..but can you tell me how??
    – JinaneK
    Commented Oct 27, 2015 at 19:21
  • On the ui part : a simple form with fields needed On server side : functions to retreive needed informations and either return them using function or using templated html. If it doesn't make sens I can try to make you a simple example. Are you familiar with AngularJs basics ?
    – niwox
    Commented Oct 27, 2015 at 19:34

1 Answer 1

0

In case you want to build your own form
Code.gs

function doGet() {
  return HtmlService.createTemplateFromFile('index').evaluate()
      .setTitle('MyTitle')
      .setSandboxMode(HtmlService.SandboxMode.IFRAME);
}

function getEmail(){
  return Session.getActiveUser().getEmail();
}

function test(){
  Logger.log(Session.getActiveUser().getEmail());
}

index.html

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <form>
      email: <br>
      <input name="firstname" id="email">
      <br>
      name:<br>
      <input type="text" name="lastname"><br>
      <button> send </button>
</form>

<script>
google.script.run.withSuccessHandler(onSuccess).getEmail();

function onSuccess(email){
  var elem = document.getElementById("email");
  elem.value = email;
}

</script>
  </body>
</html>
2
  • Thank you @niwox..I've tried both on script editor & on testing getting this : Script function not found: doGet How will be able to deploy it?
    – JinaneK
    Commented Oct 28, 2015 at 1:54
  • make sure to run the function getEmail from the script to authorize it
    – niwox
    Commented Oct 28, 2015 at 8:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.