Submitting Form on Google Sheets

336 views
Skip to first unread message

Bennett, Scott

unread,
Apr 16, 2021, 8:13:16 AM4/16/21
to google-apps-sc...@googlegroups.com
I made a sidebar form on google sheets for data entry.  It works fine for me.  I can use it without any problems.  I shared it with a coworker so he can do data entry and it will not process the form.  I keep getting formObject.name not defined. It happens to the co-worker and not me.  I manually run the processForm function from the IDE and approved all the permissions.  
It still will not run.  

function processForm(formObject){ 
  var sheet = SpreadsheetApp.getActiveSheet();
  var lrow=sheet.getLastRow()+1
  sheet.appendRow([formObject.name,
   `=VLOOKUP($A${lrow},Sheet2!$A$1:$B$89,2,False)`,                           ,
                formObject.age,
                formObject.date,
                formObject.pacertest,
                formObject.isometricpushup,
                formObject.pushup,
                formObject.shoulderstretch,
                formObject.sandrRL,
                formObject.sandrLL,
                formObject.curlups,
                formObject.extendedarmhang,
                formObject.mile,
                formObject.pullups,
                formObject.notes
                //Add your new field names here
                ]);
}

//INCLUDE HTML PARTS, EG. JAVASCRIPT, CSS, OTHER HTML FILES
function include(filename) {
  return HtmlService.createHtmlOutputFromFile(filename).getContent();
}

Sidebar.html file
<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <div class="container">
  <form id="myForm" onsubmit="handleFormSubmit(this)">
      <br>
    <label for="name">Name</label>
    <select type = "text" id="name" name="name">
      <option value="null">Select Student</option>
      <option value="123456">Doe, John</option>
      <option value="123457">Smith, William</option>
 

    </select>
    <br>
   
    <label for="age">Age</label>
    <select type="number" id="age" name="age">
      <option value="null"></option>
      <option value="14">14</option>
      <option value="15">15</option>
      <option value="16">16</option>
      <option value="17">17</option>
      <option value="18">18</option>
      <option value="19">19</option>
      <option value="20">20</option>
      <option value="21">21</option>
    </select>
    <br>
    
    <label for="date">Date:</label>
    <input type="date" id="date" name="date"
            min="2020-01-01">
    <br>
   
    <label for="pacertest">Pacer Test:</label>
    <input type="number" id="pacertest" name="pacertest"
          min = "0" max="15">
    <br>
   
    <label for="isometricpushup">Iso Pushup:</label>
    <input type="number" id="isometricpushup" name="isometricpushup" 
            min="0" max="30">
    <br>
    
    <label for="pushup">Pushup:</label>
    <input type="number" id="pushup" name="pushup"
          min="0" max="30">
    <br>
    
    <label for="shoulderstretch">Shoulder Str:</label>
    <select type="text" id="shoulderstretch" name="shoulderstretch">
    <option value="null"></option>
    <option value="pass">Pass</option>
    <option value="fail">Fail</option>
    </select>
    <br>
   
    <div>Back Saver Sit and Reach</div>
    <label for="sandrRL">R:</label>
    <input type="number" id="sandrRL" name="sandrRL"
            min="0" max="45" step=".5">
    <label for="sandrLL"> L:</label>
    <input type="number" id="sandrLL" name="sandrLL"
            min="0" max="30" step=".25" >
    <br>
   
    <label for="curlups">Curl Ups:</label>
    <input type="number" id="curlups" name="curlups"
          min="0" max="99">
    <br>
    
    <label for="extendedarmhang">Ext Arm Hang:</label>
    <input type="text" id="extendedarmhang" name="extendedarmhang"
          >
    <br>
    <br>
    <label for="mile">Mile:</label>
    <input type="text" id="mile" name="mile">
    <br>
    
    <label for="pullups">Pull Ups:</label>
    <input type="number" id="pullups" name="pullups"
          min="0" max="99">
    <br>
    
    <textarea id="notes" name="notes" placeholder="Notes" rows="5" cols="30"></textarea>

    <button type="submit" class="btn btn-primary">Submit</button>

  </form>
</div>


  </body>
</html>


--
Scott Bennett

sben...@bbchs.org

unread,
Apr 16, 2021, 8:40:43 AM4/16/21
to Google Apps Script Community

I did not include all the code.  Since it works for me, I am assuming it is an account setting/permission I am missing.

Alan Wells

unread,
Apr 16, 2021, 9:46:25 AM4/16/21
to Google Apps Script Community
It seems like something is blocking "this" from being sent to the server.
<form id="myForm" onsubmit="handleFormSubmit(this)">

Your client side function handleFormSubmit(this) doesn't seem to be sending "this".
Is the person who is having the issues using a different browser they you?
Do they have add blocker/ script blocker / malware blocker installed?

You could try removing the "onsubmit" attribute from the form tag and get the form object a different way.

window.handleFormSubmit = function() {
  var formObject;

  formObject = document.getElementById("myForm");

  google.script.run.handleFormSubmit(formObject);

Bennett, Scott

unread,
Apr 16, 2021, 11:43:33 AM4/16/21
to google-apps-sc...@googlegroups.com
Alan,
Am I right in assuming this would all be in the script tag of the html file?

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/4af5d5cc-8bbd-4c81-a530-a847fc3e939an%40googlegroups.com.


--
Scott Bennett
Data and Assessment Coordinator/Math Teacher
Bradley-Bourbonnais Community High School

Alan Wells

unread,
Apr 16, 2021, 11:56:06 AM4/16/21
to Google Apps Script Community
Yes, the function example that I'm proposing would go inside a script tag.
You already have a handleFormSubmit  function in a script tag somewhere.
Chances are that your current handleFormSubmit function looks like:

function handleFormSubmit() {

Instead of:
window.handleFormSubmit = function() {

I always put the functions inside the window object because the documentation suggests doing it that way.
Reply all
Reply to author
Forward
0 new messages