admin管理员组文章数量:1297044
I have a form with a Name and an Email address, that the user can fill out.
Now if the user clicks the submit button, I want to send the data to a spreadsheet ideally without using some server-side magic..
This is my Form:
<form method="post" action="SOME-ACTION-HERE" accept-charset="UTF-8">
<input type="text" name="newletter_name" placeholder="Name">
<input type="text" name="newletter_email" placeholder="Email">
<input type="submit" value="Subscribe" />
</form>
Is there a way to do this with my own custom HTML-form. I know that you can create a google form for a given spread sheet, but I want to use it like some sort of widget.
I have a form with a Name and an Email address, that the user can fill out.
Now if the user clicks the submit button, I want to send the data to a spreadsheet ideally without using some server-side magic..
This is my Form:
<form method="post" action="SOME-ACTION-HERE" accept-charset="UTF-8">
<input type="text" name="newletter_name" placeholder="Name">
<input type="text" name="newletter_email" placeholder="Email">
<input type="submit" value="Subscribe" />
</form>
Is there a way to do this with my own custom HTML-form. I know that you can create a google form for a given spread sheet, but I want to use it like some sort of widget.
Share asked Feb 26, 2014 at 11:10 BesiBesi 23k24 gold badges132 silver badges229 bronze badges1 Answer
Reset to default 10Yes this is possible. Using some server side magic or not.
But what's important is to know witch server we are talking about, your server or google server, because in the end it will go server side to be stored on the spreadsheet apps :)
I think this is possible to do it in full JS (but it will be really painfull).
The solution that I propose you here is to relay on a google apps script that will handle the server side magic in a really easy way:
the demo:
the HTML code on you site:
<form id="form" method="get" action="https://script.google./macros/s/AKfycbxeKTVlTkqSGLIRphBrzACjuWlfmejbPIG7NqBxx-7Us7lnqLw/exec" accept-charset="UTF-8">
<input type="text" name="newletter_name" placeholder="Name">
<input type="text" name="newletter_email" placeholder="Email">
<input type="submit" value="Subscribe"/>
</form>
and here the google apps script:
function doGet(e){
var vals=[];
vals.push(new Date());
for(var i in e.parameter){
vals.push(e.parameter[i]);
}
SpreadsheetApp.openById("0Ao02g19G1-G-dElQQW92ekZWa0lGRGREYUpHRWQwTVE").appendRow(vals);
return ContentService.createTextOutput("added");
}
If you want to see the result you can have a look to the spreadsheet here
what you need to know:
The google apps script is here located in the spreadsheet (but that's not mandatory as in the script I call it with his id).
In order to run the script you must publish it and allow anyone to run it. When you'll do this action you will get the published URL that you need to put in your HTML code. Here its: https://script.google./macros/s/AKfycbxeKTVlTkqSGLIRphBrzACjuWlfmejbPIG7NqBxx-7Us7lnqLw/exec
Hope this is a satisfying answer for you.
本文标签: javascriptAdd basic data to a Google Spreadsheet via a simple HTML FormStack Overflow
版权声明:本文标题:javascript - Add basic data to a Google Spreadsheet via a simple HTML Form - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741647071a2390247.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论