%3c/html:form%3e,scripting a google docs form submission

I've just made such a thing. Here's a break down of my process.

I need to keep a list of quotes from different web pages, and to add some info to each quote.

My bookmarklet will dynamically generate a google form (I've just viewed the source of the real google form that I've already created), it'll automatically fill the current url, the page title, and the currently selected text, than, the form will be submitted.

Since I need to manually add info, I intentionally didn't include at least one required field, so I receive the google form with an error message (but with url, title & quote already filled). Now I can manually add all the other info that I need and submit the form.

If the bookmarklet fill all the required fields you'll just receive the google form success response "Thanks! Your response has been recorded."

I've used the following site to generate a bookmarklet that use jQuery:

http://benalman.com/code/test/jquery-run-code-bookmarklet/

(I'm using jQuery to be able to scrap additional info & content from the webpage)

To be able to use that site properly, you'll have to escape your one-liner html (you can use this escape tool)

The required steps are:

Create a google form / spreadsheets

View the source of the form and copy the fields you want the bookmarklet to fill

Escape your html and use this to write your script that fill the info, this site will create the bookmarklet for you

So in my case:

1. I've created a form that include one text field to hold the url, another text field to hold the title of the page, a paragraph text to hold the quote (the selected text). The form also include some other required fields that I fill manually.

2. I prepared the following html:

action="https://spreadsheets.google.com/spreadsheet/formResponse?formkey=XYZXYZXYZXYZXYZXYZXYZ&ifq">

(entry_0 - url, entry_3 - page title, entry_2 - quote)

3. After putting it in one line and escaping it. I've used the following script:

frm = $(unescape('%3Cform%20action%3D%22https%3A//spreadsheets.google.com/spreadsheet/formResponse%3Fformkey%3DXYZXYZXYZXYZXYZXYZXYZ%26amp%3Bifq%22%20method%3D%22POST%22%3E%0A%3Cinput%20type%3D%22text%22%20name%3D%22entry.0.single%22%20value%3D%22%22%20id%3D%22entry_0%22%20/%3E%0A%3Cinput%20type%3D%22text%22%20name%3D%22entry.3.single%22%20value%3D%22%22%20id%3D%22entry_3%22%20/%3E%0A%3Ctextarea%20name%3D%22entry.2.single%22%20id%3D%22entry_2%22%3E%3C/textarea%3E%0A%3Cinput%20type%3D%22submit%22%20name%3D%22submit%22%20value%3D%22submit%22%20/%3E%0A%3C/form%3E'));

$(frm).children('#entry_0').attr('value',location.href);

$(frm).children('#entry_3').attr('value',$('title')[0].innerHTML);

$(frm).children('#entry_2').html(window.getSelection().toString());

$(frm).children('input[type=submit]').click()

This method has been tested with chrome.

Good luck!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值