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?
-
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 WellsCommented Oct 27, 2015 at 18:58
-
@SandyGood Thanks Sandy, I need only to show these fields (the user won't change them)– JinaneKCommented 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– niwoxCommented Oct 27, 2015 at 19:19
-
I'm willing to learn & will be patient in applying @niwox..but can you tell me how??– JinaneKCommented 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 ?– niwoxCommented Oct 27, 2015 at 19:34
Add a comment
|
1 Answer
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>