将URL参数传递到HTML表单Google Web App [英] Pass URL Parameters to HTML Form 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=###
. - 在此修改中,我使用
google.script.url.getLocation()
检索查询参数. - In this modification, I used
google.script.url.getLocation()
for retrieving the query parameter.
如果我的理解是正确的,那么这个答案如何?请认为这只是几个答案之一.
If my understanding is correct, how about this answer? Please think of this as just one of several answers.
请如下修改
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屋!
- The URL is like
- URL类似于