Created
November 14, 2025 13:12
-
-
Save phillypb/9bb88c01716d2270bf03373e5b7085f4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Main Function to get submitted Google Form data. | |
| * | |
| */ | |
| function getFormData(e) { | |
| // get all values from submitted Form | |
| var originalNamedValues = e.namedValues; | |
| console.log(originalNamedValues); | |
| // call Function to cleanse Form data | |
| var cleanedFormData = cleanseData(originalNamedValues); | |
| // you MUST use the new, all-lowercase, trimmed question titles going forwards | |
| var name = cleanedFormData['name'][0]; | |
| console.log("name is: " + name); | |
| var shoeSize = cleanedFormData['shoe size'][0]; | |
| console.log("shoeSize is: " + shoeSize); | |
| var aDate = cleanedFormData['a date'][0]; | |
| console.log("aDate is: " + aDate); | |
| }; | |
| /** | |
| * Function to clean Form questions. | |
| * - set to lowercase | |
| * - trim any whitespace | |
| */ | |
| function cleanseData(originalNamedValues) { | |
| // new empty JavaScript Object for cleansed data | |
| var cleanedNamedValues = {}; | |
| // loop through each original key (question title) and run a Function to clean it | |
| Object.keys(originalNamedValues).forEach(function (originalKey) { | |
| // cleanse the key (question title) | |
| var cleanedKey = originalKey.toLowerCase().trim(); | |
| console.log("cleanedKey is: " + cleanedKey); | |
| // get the value that pairs with this question | |
| var value = originalNamedValues[originalKey]; | |
| // add the value to the new JavaScript Object using the new cleaned key | |
| cleanedNamedValues[cleanedKey] = value; | |
| }); | |
| // log Object of cleansed data | |
| console.log(cleanedNamedValues); | |
| // return to Parent Function | |
| return cleanedNamedValues; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment