将URL参数传递到HTML表单Google Web App [英] Pass URL Parameters to HTML Form Google Web App

本文介绍了将URL参数传递到HTML表单Google Web App的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经解决了与此有关的大多数相关问题,但还没有找到一种对我有帮助的解决方案(我已逐一应用它们).我有一个HTML表单,正在通过Google作为网络应用发布.我需要用该参数预填充输入框.

I've gone through most of the relating questions regarding this and haven't found a solution that helps me (I've applied them one by one). I have an HTML form that I am publishing as a web app through google. I need to prefill an input box with that parameter.

code.gs

function doGet() {
return HtmlService
        .createTemplateFromFile('html')
        .evaluate();      
          }

html.html

html.html

<!DOCTYPE html>
<html>
<head>
</head>
<style>
</style>
<body>
<form>
  <h1><center>Verification</center></h1>
  Form ID:<input type="number" name="formid" id="formid" class="formid">
</form>
</body>
</html>

正如我所说,我曾在类似的问题上尝试过许多建议,但似乎找不到可行的建议. id是我可以输入url +?formid =并将其填充到输入中.我怎样才能像描述的那样做到这一点?

As I said, I've tried many suggestions in similiar questions, but can't seem to find one that works. The id is that I can type in my url + ?formid= and have that populate in the input. How can I make this happen as described?

谢谢!

推荐答案

  • 使用URL url + ?formid=###访问Web Apps时,您要将###的值放在文本框中.
    • URL类似于https://script.google.com/macros/s/###/exec?formid=###.
      • When Web Apps is accessed with the URL of url + ?formid=###, you want to put the value of ### to the text box.
        • The URL is like https://script.google.com/macros/s/###/exec?formid=###.
        • 如果我的理解是正确的,那么这个答案如何?请认为这只是几个答案之一.

          If my understanding is correct, how about this answer? Please think of this as just one of several answers.

          • 在此修改中,我使用google.script.url.getLocation()检索查询参数.
          • In this modification, I used google.script.url.getLocation() for retrieving the query parameter.

          请如下修改html.html.

          <!DOCTYPE html>
          <html>
          <head>
          </head>
          <style>
          </style>
          <body>
          <form>
            <h1><center>Verification</center></h1>
            Form ID:<input type="number" name="formid" id="formid" class="formid">
          </form>
          <script>
            google.script.url.getLocation(function(location) {
              document.getElementById("formid").value = location.parameters.formid[0];
            });
          </script>
          </body>
          </html>
          

          • 通过上述修改,当您使用https://script.google.com/macros/s/###/exec?formid=12345访问Web Apps时,12345会放置在文本框中.
            • By above modification, when you accessed to Web Apps with https://script.google.com/macros/s/###/exec?formid=12345, 12345 is put to the text box.
            • 如果我误解了您的问题,而这不是您想要的方向,我深表歉意.

              If I misunderstood your question and this was not the direction you want, I apologize.

              这篇关于将URL参数传递到HTML表单Google Web App的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆