Skip to content

Datathon ‐ Google Forms

Shreyas Rao edited this page Nov 19, 2024 · 3 revisions

To collect responses from our Datathon Participants and Volunteers, we make use of the following Google Forms to collect and process their response. These forms will most likely be created by the Events Team, but the Web Dev will assist in the deployment of the Participant & Volunteer Registration Forms. There are certain requirements and configurations to consider with these forms:

Participant Registration

This will be the first form, that can be filled out by a potential participant. The Web Dev will need to ensure the following fields are being collected with the appropriate response validations.

Response Validation

These fields must exist on the forms, with the correct level of Response Validation as indicated in the table below.

Form Field Response Validation
First Name N/A
Last Name N/A
Email Check if the input is Text and Email else provide this message: Invalid email
Phone Number Use a Regex to see if the input matches ^[\+]?[(]?[0-9]{3}[)]?[0-9]{3}[0-9]{4,6}$ else provide this message: Invalid Phone Number
School Only allow for one selection else provide this message: Select only 1 from above
Country of Residence Only allow for one selection else provide this message: Select only 1 from above
Dietary Restrictions N/A

Script Editor

To collect the latest response from the form and store it on MongoDB Atlas, we will set a WebHook Request that sends a POST request to our server to save the response.

This is an example implementation used for the 2024 Datathon Form.

var POST_URL = "https://datathon-ops.ds3utsc.com/api/registration";   // URL of that accepts a POST Request
const VALIDATION_SECRET = "<insert-validation-secret>";             // Used to verify if requests are authentic or not
var payload = {};

function onSubmit(e) {
  const form = FormApp.getActiveForm();
  const allResponses = form.getResponses();
  const latestResponse = allResponses[allResponses.length - 1];
  const response = latestResponse.getItemResponses();

  // Collects the specific fields needed from the submission
  for (var i = 0; i < response.length; i++) {
    var question = response[i].getItem().getTitle();
    var answer = response[i].getResponse();
    switch (question) {
      case "📛 First Name":
        payload["firstName"] = answer;
        break;
      case "📛 Last Name":
        payload["lastName"] = answer;
        break;
      case "📧 Email":
        payload["email"] = answer;
        break;
      case "🏫 School":
        payload["school"] = answer[0];
        break;
      case "📞 Phone Number":
        payload["phoneNum"] = answer;
        break;
      case "🌎 Country of Residence":
        payload["countryOfResidence"] = answer[0];
        break;
      case "🥞 Do you have any dietary restrictions?":
        payload["dietaryRestrictions"] = answer;
        break;
    }
  }

  // POST Request
  var options = {
    method: "post",
    headers: {
      "ds3-secret": VALIDATION_SECRET,
    },
    contentType: "application/json",
    payload: JSON.stringify(payload),
  };

  UrlFetchApp.fetch(POST_URL, options);
}

Steps

  1. Open Google Forms and navigate to the Registration Form.
  2. Click on the More button (three vertical dots) in the top-right corner of the screen.
  3. Select Script editor from the dropdown menu.
  4. Create a new App Script File by clicking the + Button.
  5. Implement the above code with any necessary changes and save changes.
  6. Move over to the Side Menu and click the Option called Trigger.
  7. Click Add Trigger.
  8. When the Modal pops up, ensure the options are as follows and click Save to deploy it.

Google Forms Script Trigger

Cleanup

  1. Open Google Forms and navigate to the Registration Form.
  2. Click on the More button (three vertical dots) in the top-right corner of the screen.
  3. Select Script editor from the dropdown menu.
  4. Move over to the Side Menu and click the Option called Trigger.
  5. Hover over the trigger and click on the More button (three vertical dots) on the right-hand side
  6. Select Delete Trigger

Volunteer Registration

This will be the form that will be filled out by volunteers. The Web Dev will need to ensure the following fields are being collected with the appropriate response validations. Once enough volunteers exist, the Web Dev Team will require a list of Emails from the Events Team to create Login Credentials for each volunteer to access the Admin Site for QR Code Scanning.

Response Validation

These fields must exist on the form, with the correct level of Response Validation as indicated in the table below.

Form Field Response Validation
Email Check if the input is Text and Email else provide this message: Invalid email

Clone this wiki locally