Is there a way to create an output form based on Google Sheets data? - forms

What I want to make
Is this possible?
I'd like to create an output form that reads data from a Google Sheets spreadsheet. In the form, users would enter a few values (entering their name and some ID number, for example) and view the corresponding information in the connected spreadsheet but not any other information in the sheet. Something like an output form in Microsoft Access. I'm hoping there's a way to accomplish this in Google Sheets using existing tools and maybe some scripting.
More generally, though, any way to create this type of 'limited visibility' on a per-user basis for Google Sheets data would be useful. (The 'protect sheet' function in the menu doesn't accomplish this; see below.)
For reference, my specific use case at the moment is as a teacher and wanting a way for students to see specific information related to them from my student information spreadsheet but while not revealing other students' information. I would have a simple form where they enter a name and maybe some personalized code that I give them so they can see their attendance record or something else. For my purposes, I don't need the form to be extremely secure as none of the information is all that sensitive (although more secure is better), but I don't want to be just putting all the information there in front of them by giving them access to the entire sheet.
What I've tried so far
I made a new spreadsheet file with two sheets; one sheet was visible to function as a form, and the second sheet was not visible (which I accomplished via the 'protect' menu option). I used importrange() to read in the relevant data from my primary spreadsheet to the new spreadsheet's non-visible sheet. On the visible sheet, students entered their name from a drop-down and entered their student ID as validation. If the student's name and ID matched, the first sheet did a vlookup() to read in information from the protected sheet and some information from their student record.
Here's what I made, in case my description doesn't make sense: https://drive.google.com/open?id=1cHO2jzMh1mkXvlLh-M4eYqN7v11t95-GnfWqL5IwQ14&authuser=0
This had two problems, one small and one big.
The small problem was that every student could see the "form" sheet at the same time. If two students opened the spreadsheet at the same time they would see any information that the other student had entered. I handled this by writing a simple script to automatically reset the "form's" input cells after 20 seconds. Also, any time the form was opened by a new person, the "form's" output cells were erased. So, obviously not a brilliant solution, but for my purposes, this was mostly good enough.
The big problem was that Google's own preview viewer (built into Google Drive and the like) ignores protected ranges and sheets and displays the entire contents a spreadsheet. (Normally, protected sheets are not visible at all and don't appear in the list of sheets at the bottom of the screen unless the viewer has access to them.)
In my case this meant included the protected one that shouldn't have been visible at all, rendered as if it were a print preview, meaning the students were actually able to view all of the other students' data in one big table.

Are you familiar with Web Apps?
An Apps Script Web App allows you among others to output selected Google Document contents into a browser.
Hereby, you can use the method Session.getActiveUser() to obtain the email of the user and dynamically adjust the data the user is going to obtain in function of his email (BTW, you can also use Session.getActiveUser() in the spreadsheet, to detect the user automatically instead of asking him for his name).
Simple example workflow:
Replace in column A student names through student emails (the Gmail addresses with which the users authenticate their sessions and access Google Sheets)
Bind to the spreadsheet a script with a content similar to the following:
function doGet(){
var ss=SpreadsheetApp.getActive().getSheetByName('Data');
var range=ss.getDataRange();
var values=range.getValues();
var user=Session.getActiveUser();
var output="";
for(var i=1;i<ss.getLastRow();i++){
if(values[i][0]==user){
for(var j=1;j<ss.getLastColumn();j++){
output+=(values[i][j])+" ";
}
}
}
return ContentService.createTextOutput(JSON.stringify(output));
}
Make sure that you have a doGet() function and a return statement.
After running the script once manually to trigger authorization flow, deploy it as a Web App - executing it as User accessing the web app and giving access to Anyone (unless desired otherwise).
Copy the URL of your WebApp and forward it to your student.
When the student open the URL in their browser - they will obtain their results - provided their email is listed in the sheet.
Please note that the code provided is a simple sample, that retrieves
all data and outputs it as a string. Feel free to modify the script
e.g. retrieving only columns of interest and outputting the data as a
html table, rather than a simple string.

Related

Trying to write App Script for sheets/forms to automate email response

I have a form and sheet but I'm not sure which is better to use to pull data from or create the trigger of form submit.
I am trying to create an email response to a form that is based on a google doc with images and text and will pull the name and responses from the form (or sheet).
Here are the work files. I will need to add this script to a different form/sheet later.
https://drive.google.com/drive/folders/1MhHOPjMD0JwVgP98majrKBPk-Cf1_Uwn?usp=sharing
There is actually an existing template for something related to what you are asking for in this Google developer documentation https://developers.google.com/apps-script/samples/automations/content-signup where you can easily make a copy of the file and change the values based on what you need.
This is basically allowing you to send emails from a trigger "onFormSubmit" based on what people filled in the Google form. Please let me know if you actually need the full code though! Or what exactly you are trying to achieve if the template is not working for you.

Place Autocomplete Address Form

I created a registration form for a website and I included the Place Autocomplete Address Form provided by Google to fill the Country, Province and City fields.
It works perfectly. However, I use Google Analytics and I have seen that a certain number of users leave the process before completing the registration, as if something went wrong and couldn’t complete it.
The form itself is quite simple, so I checked it with some possible errors.
It has several requested fields, so the form reloads partially to display a popup asking you to add the information or data in each case. The fields filled out correctly keep de information. All but the ones filled out by the Google API, which simply disappear. And I am not talking about the information added to them, the fields themselves are missing, removed from the code.
Any suggestion?
I created a registration form.
Some fields (Country, Province and City) are filled by this API:
Place Autocomplete Address Form
The code I used is on that page.
If you fill out the form and make any mistake or fail to fill any requested field, for instance, adding different passwords in the Password and Re-write Password fields, the form realoads partially displaying a message requesting you to fill them properly.
By them, the fields to be filled by the Google API are gone, removed from the code.
The problem is that when the user filled the, in the example, password and re-write password fields properly, another message popups requesting to fill the country, province and city fields.
Is it clear enough now?

How to automatically assign/generate/increment an ID number into Google Form responses, so that respondents can access their own forms based on it?

I would like to set up a (Google) form-filling system, that essentially has to be accessed and filled two times (before and after the completion of a project). I would like to create a form one can return to by filling in an ID number.
For that, I would need a script that automatically generates an ID number for each respondent. I have found 'Google Apps Script for Form, Generate Unique ID Number', but I couldn't get it to work (I am not good at scripting yet). I would like to be able to decide how the ID numbers are generated (for example to have non-numeric characters as well, e.g. XYZ000000001, XYZ00000002, XYZ00000003, etc.)
The reason I want to do this is so that respondents can access their own responses based on the ID assigned to Them. I found two possible solutions, but again, I can't manage them. One code is the 'Class FormResponse' that fetches the existent information (if I understand it well enough), and the other is 'Generate unique Form URL for each respondent' which generates a unique URL for each respondent. That would work fine, but I still need the IDs for easier data maintenance.
This is a lot of code and I'm not sure if it makes sense to combine all of it. Perhaps there is an easier way to achieve what I want with a way simpler script. I will break down the process as I imagine it, into steps:
Send a form to AA#zive.com,BB#zive.com,CC#zive.com.
For example, BB only has a project planned, so BB receives the form which asks: Is Your project planned or completed?
BB chooses the first option and fills in the details.
BB gets a unique ID which is inserted into the first column of the responses.
The ID is sent back in a response email to BB (perhaps the linked script can be tweaked to send the unique ID).
After a couple of months, BB has completed the project, so BB goes back to the form, either via the same email sent in step 1, or the same form embedded on a website.
BB now chooses the second option, since the project is completed.
The form asks for the ID number, BB fills it.
All of BB's answers now go to the row with the matching ID, overwriting certain fields if necessary...
I am aware that this might be a bit complex, but any even partial answer accompanied by some snippets of code would be highly appreciated. I will gladly share it once I manage to compile the whole idea. :)
Google Forms doesn't allow respondents to search previous sent responses. The only way that they can access a previously submitted response is by the edit response URL. To get this URL programmatically, use getEditResponseUrl.
You could send this URL by an email. For details see How to add "Edit Response" link to Google Forms emails?

Using ninja forms, how can I persist field values across pages?

I have a form on the home page of quotedjobs.com that I would like to persist the field values of across pages.
For example: A user enters some values in fields, such as job title (textbox), job type (list) and job description (text field). Underneath that I ask users to register on the site, but they have the option to click a link to allow them to login if they are already members.
What I would like to be able to do, is to redirect users to another form that is a copy, but allows them to login instead of register, but keep hold of the values that they entered in the title, type and description form of the previous page so they aren't losing their work.
I have seen the ninja_forms_processing variable in the docs, but I'm not clear on how to use that.
TL;DR - You can't.
As it was slim pickings here, I sent an email over to support. Got this response:
Hello,
At this time this use case is not possible in Ninja Forms. The plugin is currently unable to transfer data from field to field or between forms.
I’m sorry that we do not have a better solution for you at this time.
Thank you,

Fill document from a google spreadsheet

I have a web form that populates a Google spreadsheet.
My question is can I populate a document with some or all of the information from a given row ?
Example: I created a webpage for a small business that they can input all the details from a sale. That populates a google spreadsheet. Now I need to create a nice looking receipt (document) that includes the information from some of the fields in a particular row of that google spreadsheet to print out and give to the costumer for them to sign
I coded a simple java script library todo the same thing after hours of search. (Wish I started it right away) Gsheet2json
Upto now it can get data from the spreadsheet as objects array or arrays of array and you can use any template you want to publish it(of cause using your own java script + html).