【问题标题】:Any update with Google apps, because script has stopped working?Google 应用程序有任何更新,因为脚本已停止工作?
【发布时间】:2016-05-08 02:42:05
【问题描述】:

谁能帮忙解决一个停止工作的脚本:

这是一个(去年)创建的 html/css 表单,用于在 google 电子表格上获取响应以及在文件夹中上传的文件。直到今年年初它都工作得很好,但现在不行了。我的意思是像往常一样,我运行一个函数+部署应用程序,我得到链接并出现表单,但提交后我什么也没得到,空白页和电子表格不包含任何内容。 非常感谢您的指导。

这是我的代码:

Form.html

<script>
  // Javascript function called by "submit" button handler,
  // to show results.
  function updateOutput(resultHtml) {
    toggle_visibility('inProgress');
    var outputDiv = document.getElementById('output');
    outputDiv.innerHTML = resultHtml;
  }

  // From blog.movalog.com/a/javascript-toggle-visibility/
  function toggle_visibility(id) {
    var e = document.getElementById(id);
    if(e.style.display == 'block')
      e.style.display = 'none';
    else
      e.style.display = 'block';
  }
</script>


<link href='http://fonts.googleapis.com/css?family=Bitter' rel='stylesheet' type='text/css'>
<style type="text/css">

img {
      display: block;
      margin-left: auto;
      margin-right: auto;
      width:500px;
      height:170px;
     ;
}

form {
    width:450px;
    padding:30px;
    margin: auto;
    background: #FFF;
    border-radius: 10px;
    -webkit-border-radius:10px;
    -moz-border-radius: 10px;
    box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.13);
    -moz-box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.13);
    -webkit-box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.13);
}

h2 {
    width:450px;
    padding:30px;
    margin: auto;
    margin-top: 5px;
    margin-bottom: 10px;
    text-align: center;
    border-radius: 10px;
    background: #FF8500;
    color: #fff;
    box-shadow: 1px 1px 4px #DADADA;
    -moz-box-shadow: 1px 1px 4px #DADADA;
    -webkit-box-shadow: 1px 1px 4px #DADADA;
    border-radius: 10px;
    -webkit-border-radius: 10px;
    -moz-border-radius: 10px;
}

h1 {
    background: #2A88AD;
    padding: 20px 30px 15px 30px;
    margin: -30px -30px 30px -30px;
    border-radius: 10px 10px 0 0;
    -webkit-border-radius: 10px 10px 0 0;
    -moz-border-radius: 10px 10px 0 0;
    color: #fff;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.12);
    font: normal 30px 'Bitter', serif;
    -moz-box-shadow: inset 0px 2px 2px 0px rgba(255, 255, 255, 0.17);
    -webkit-box-shadow: inset 0px 2px 2px 0px rgba(255, 255, 255, 0.17);
    box-shadow: inset 0px 2px 2px 0px rgba(255, 255, 255, 0.17);
    border: 1px solid #257C9E;
}

h1 > span {
    display: block;
    margin-top: 2px;
    font: 13px Arial, Helvetica, sans-serif;
}

label {
    display: block;
    font: 13px Arial, Helvetica, sans-serif;
    color: #888;
    margin-bottom: 15px;
}

input[type="text"],
input[type="email"],
input[type="file"],
textarea,
select {
    display: block;
    box-sizing: border-box;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    width: 100%;
    padding: 8px;
    outline: none;
    border: 1px solid #B0CFE0;
    -webkit-transition: all 0.30s ease-in-out;
    -moz-transition: all 0.30s ease-in-out;
    -ms-transition: all 0.30s ease-in-out;
    -o-transition: all 0.30s ease-in-out;
}

section{
    font: normal 20px 'Bitter', serif;
    color: #2A88AD;
    margin-bottom: 5px;
}

section span {
    background: #2A88AD;
    padding: 5px 10px 5px 10px;
    position: absolute;
    border-radius: 50%;
    -webkit-border-radius: 50%;
    -moz-border-radius: 50%;
    border: 4px solid #fff;
    font-size: 14px;
    margin-left: -45px;
    color: #fff;
    margin-top: -3px;
}

input[type="button"], 
input[type="submit"]{
    background: #2A88AD;
    padding: 8px 20px 8px 20px;
    border-radius: 5px;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    color: #fff;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.12);
    font: normal 30px 'Bitter', serif;
    -moz-box-shadow: inset 0px 2px 2px 0px rgba(255, 255, 255, 0.17);
    -webkit-box-shadow: inset 0px 2px 2px 0px rgba(255, 255, 255, 0.17);
    box-shadow: inset 0px 2px 2px 0px rgba(255, 255, 255, 0.17);
    border: 1px solid #257C9E;
    font-size: 15px;
}
input[type="button"]:hover, 
input[type="submit"]:hover{
    background: #2A6881;
    -moz-box-shadow: inset 0px 2px 2px 0px rgba(255, 255, 255, 0.28);
    -webkit-box-shadow: inset 0px 2px 2px 0px rgba(255, 255, 255, 0.28);
    box-shadow: inset 0px 2px 2px 0px rgba(255, 255, 255, 0.28);
}


</style>

<div id="formDiv">
<!-- Form div will be hidden after form submission -->
<img src="http://www.greenman-advertising.com/wp-content/uploads/2013/08/header_problemSolving_03.jpg">
<form id="myForm" runat="server">
<h1>Job application<span>Apply now and get the opportunity to join us!</span></h1>
<section> <span>1</span>Personal details</section>
    Full name: <input type="text" name="name" placeholder="First name & Last name"/><br/>
    Date of birth: <input type="text" name="birth" placeholder="dd/mm/yyyy"/><br/>
    Nationality:  <select name="nationality">
    <option>Test1</option>
    <option>Test2</option>
    <option>Test3</option>
     </select><br/>
     Marital status:  <select name="marital">
    <option>...</option>
    <option>Married</option>
    <option>Single</option>
         </select><br/>
    Please state the age of your children who will be registered in our school: <input type="text" name="children" placeholder="Example: 5;9;12 or 0"/><br/>

    <section> <span>2</span>Experiences and qualifications</section>
    Years of experience:  <select name="years">
    <option>3</option>
    <option>4</option>
    <option>5</option>
    <option>6</option>
    <option>7</option>
    <option>8</option>
    <option>9</option>
    <option>10</option>
    <option>10+</option>
    </select><br/>
    Highest qualification obtained: <input type="text" name="qualification" placeholder="Example: Degree, Master, .."/><br/>
    Educational qualification obtained: <input type="text" name="educational" placeholder="Example: QTS,PGCE,CELTA, .."/><br/>
    English language level:  <select name="profiency">
    <option>...</option>
    <option>Fluent English proficient</option>
    <option>Advanced</option>
     <option>Intermediate</option>
    <option>Early intermediate</option>
    <option>Beginner</option>
    </select><br/>
    <section> <span>3</span>Position applied for</section>
    Subject:  <select name="subject">
    <optgroup label="Teaching">
    <option>...</option>
    <option>Arts</option>
    <option>Biology</option>
    <option>Chemistry</option>
    <option>Computer Science</option>
    <option>English</option>
    <option>Math</option>
    <option>Physics</option>
    <option>Science</option>
    <option>Social Studies</option>
    </optgroup>
    <optgroup label="Other">
    <option>...</option>
    <option>Principal</option>
    <option>Deputy principal</option>
    <option>Educational spervisor</option>
    </optgroup>
    </select><br/>
    Grade level ( or Section):  <select name="grade">
    <option>...</option>
    <option>Higher grades</option>
    <option>Lower grades</option>
    <option>IGCSE</option>
    <option>AS</option>
    <option>A2</option>
    <option>SAT</option>
    </select><br/>
<section> <span>4</span>Contact details</section>
    Email: <input type="email" name="email" placeholder="example@domain.com"/><br/>
    Phone number: <input type="text" name="phone" placeholder="[+]code country/phone number"/><br/>
    Skype: <input type="text" name="skype" placeholder="username"/><br/>
<section> <span>5</span>Attachments</section>
    CV (pdf/doc/docx only): <input type="file" name="myFile"/><br/>
    Qualification (scan): <input type="file" name="myFile2"/><br/>
    Other qualification (scan): <input type="file" name="myFile3"/><br/>
    Passport (scan): <input type="file" name="myFile4"/><br/>
    <input type="submit" value="Apply"
      onclick="toggle_visibility('formDiv'); toggle_visibility('inProgress');
        google.script.run
          .withSuccessHandler(updateOutput)
          .processForm(this.parentNode)" /><br/>
</form>
</div>

<div id="inProgress" style="display: none;">
<!-- Progress starts hidden, but will be shown after form submission. -->
Uploading. Please wait...
</div>

<div id="output">
  <!-- Blank div will be filled with "Thanks.html" after form submission. -->
</div>

代码.gs

var submissionSSKey = '1urIXPV2NdsqTJ5zXJb1_t_EdsY7Kuh3VcSBJ4cnPIEg';
var folderId = "0B0lYW3YSUvX2ZDc0WnhJdFhkQk0";

function doGet(e) {
  var template = HtmlService.createTemplateFromFile('Form.html');
  template.action = ScriptApp.getService().getUrl();
  return template.evaluate();
}


function processForm(theForm) {
  var fileBlob = theForm.myFile;
  var fileBlob2 = theForm.myFile2;
  var fileBlob3 = theForm.myFile3;
  var fileBlob4 = theForm.myFile4;
  
  var folder = DriveApp.getFolderById(folderId);
  var doc = folder.createFile(fileBlob);
  var doc2 = folder.createFile(fileBlob2);
  var doc3 = folder.createFile(fileBlob3);
  var doc4 = folder.createFile(fileBlob4);


  // Fill in response template
  var template = HtmlService.createTemplateFromFile('Thanks.html');
  var name = template.name = theForm.name;
  var birth = template.birth = theForm.birth;
  var nationality = template.nationality = theForm.nationality;
  var marital = template.marital = theForm.marital;
  var children = template.children = theForm.children;
  var years = template.years = theForm.years;
  var profiency = template.profiency = theForm.profiency;
  var qualification = template.qualification = theForm.qualification;
  var educational = template.educational = theForm.educational;
  var subject = template.subject = theForm.subject;
  
  var grade = template.grade = theForm.grade;
  var email = template.email = theForm.email;
  var phone = template.phone = theForm.phone;
  var skype = template.skype = theForm.skype;

  var fileUrl = template.fileUrl = doc.getUrl();
  var fileUrl2 = template.fileUrl = doc2.getUrl();
  var fileUrl3 = template.fileUrl = doc3.getUrl();
  var fileUrl4 = template.fileUrl = doc4.getUrl();

  // Record submission in spreadsheet
  var sheet = SpreadsheetApp.openById(submissionSSKey).getSheets()[0];
  var lastRow = sheet.getLastRow();
  var targetRange = sheet.getRange(lastRow+1, 1, 1, 18).setValues([[name,birth,nationality,marital,children,profiency,years,qualification,educational,subject,grade,email,phone,skype,fileUrl,fileUrl2,fileUrl3,fileUrl4]]);

  // Return HTML text for display in page.
  return template.evaluate().getContent();
}

谢谢.html

<div>
    <h2>Thank you <?= name ?>, <br>your application has been received.</h2>
</div>

【问题讨论】:

  • 我不确定您是否需要这个:template.action = ScriptApp.getService().getUrl(); 这可能会导致错误。另外,您不需要doGet(e) 中的e。你可以删除它。
  • 我会从表单标签中删除runat="server"
  • 吹毛求疵:您粘贴的大量代码与问题无关。在未来的 Stack Overflow 帖子中更容易将其编辑为有问题的函数/代码。

标签: javascript html google-apps-script


【解决方案1】:

是的,最近发生了一些变化。默认沙盒模式现在为IFRAME。您的doGet() 函数未指定沙盒模式,因此它现在默认为IFRAME。这改变了表单的行为。您有一个&lt;input&gt; 标签,它是submit 类型的按钮。这会导致表单在提交表单时发出 GET 或 POST 请求。这会导致屏幕变为空白,并且可能干扰了对服务器的google.script.run.myfunction() 调用。将输入按钮类型从submit 更改为button

目前:

<input type="submit" value="Apply"

改为:

<input type="button" value="Apply"

我修改了名为toggle_visibility的函数的代码

if(e.style.display !== 'none')//Modified this line

曾经:

if(e.style.display === 'block')

样式可以有许多不同的设置。例如,如果它是inline,那么这会破坏代码。但如果是!== "none",那么如果不是none,那么显然是在显示。

这是一个共享的 Apps 脚本文件的链接:

Link to Shared Apps Script File

【讨论】:

  • 非常感谢,一如既往的第一时间提供帮助。我已经按照您的建议进行了更改。至于功能,您能否给我进一步的指导(我该怎么做才能使它工作?),因为我已经设法在没有深入了解所有问题的情况下完成了所有这些工作。再次感谢
【解决方案2】:

根据您的建议,我访问了此页面Migrating to IFRAME Sandbox Mode

并进行了以下更改:

function doGet() {
var template = HtmlService.createTemplateFromFile('Form.html');
template.action = ScriptApp.getService().getUrl();
return template.evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME);
}

我将类型更改为“按钮”,但没有发生任何事情:它一直在“上传。请稍候...”

【讨论】:

  • 我永远不会看到你的答案,除非我碰巧看到这个问题现在有两个答案,然后看了一下。如果您发表评论,则会显示在我的收件箱中。
  • 对不起,我的意思是我已经尝试了几个月,但还是没有找到工作,一个真正的新手,虽然我已经设法到处寻找。你介意帮我桑迪吗,那太好了!!谢谢
  • 谢谢,非常感谢
  • 我有一些工作。我创建了一个新的 Apps Script Web App。你想让我在这里公开,或者你可以看到我的个人资料,然后给我发电子邮件。
  • 也许我们可以分享它,这样人们也可以从中受益。再次感谢
猜你喜欢
  • 2014-12-08
  • 2013-08-06
  • 1970-01-01
  • 1970-01-01
  • 2013-11-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多