views:

585

answers:

4

I'm trying to create a bookmarklet that parses a page and sends the results to a googledocs spreadsheet via a form that I've defined.

The relevent bit of the script is:

var form = document.createElement("form");

form.action = "http://spreadsheets.google.com/formResponse?formkey=Fd0SHgwQ3YwSFd5UHZpM1QxMlNOdlE6MA&ifq";
form.method = "POST";
form.id="ss-form";
form.innerHTML = ["<input id='entry_0' name = 'entry.0.single' value = '" + orderDate + "'/>", "<input name = 'entry.2.single' value = '" + email + "'/>", "<input name = 'entry.3.single' value = '" + customerID + "'/>", ].join("");
form.submit();


alert(form.innerHTML);

// returns:

Nothing is being saved to the form via the bookmarklet - any way to capture google's response in my bookmarklet's code? (fwiw, i've injected jQuery via jQueryify)

EDIT:

Firebug's Net panel isn't hearing any of the activity triggered by the bookmarklet - How about i approach this from goolgle's viewform method instead of formresponse.

The form i'm trying to submit is located at:

http://spreadsheets.google.com/viewform?hl=en&amp;formkey=dFd0SHgwQ3YwSFd5UHZpM1QxMlNOdlE6MA

How can I go about injecting the script values into that form and then submitting that - again...via script within the bookmarklet that would have been triggered while on the page being parsed?

+4  A: 

if your already using jquery, try submitting the form via ajax ($.ajax). You can setup a success function that will be called when google sends back their response.

alternatively you should be able to use firebug to view the response google sends back.

Specifically I was thinking you could try something like the following:

$.ajax(
  url: "http://spreadsheets.google.com/formResponse",
  data: { formkey: "Fd0SHgwQ3YwSFd5UHZpM1QxMlNOdlE6MA&ifq", entry.0.single: orderDate, entry.2.single: email, entry.3.single: customerID },
  type: "POST",
  dataType: "xml",
  success: function(data, textStatus, XMLHttpRequest) {
    console.log("success");
    console.log(data);
  },
  error: function(XMLHttpRequest, textStatus, errorThrown) {
    console.log("error");
    console.log(textStatus);
  },
)
mountainswhim
Thankx much for the added detail...i've tried a couple variations on your code - for whatever reason - 'console is undefined' so i'm just tossing stuff to an alert box:Perhaps this screen cap will help:http://screencast.com/t/ZDZhNDVmMagain...thx for the help
justSteve
you probably figured it out by now, but console is unique to the firebug plugin.
mountainswhim
A: 

I thought I had a few tidbits to add to this, but they turn out to NOT solve the problem.

  • definitely use the input 'name' (not id)
  • one of the other parameters is 'ifq', not sure how it works to bundle this with 'formkey' (a string is just a string, right?)
  • to completely mock the Google form, add these additional fields: pageNumber=0; backupCache=''; submit=Submit

I get the same '405 Method not allowed' error though...

DanDan
A: 

I don't have a complete answer, but I have been able to make it work using Curl:

curl http://spreadsheets.google.com/formResponse?formkey=dFpVLTVFY2t5dWdoNTZpNERwWDRxX2c6MQ&amp;ifq --data entry.0.single=eric --data entry.1.single=pugh

Also, I am able to have it work via Ajax using prototype, but ONLY on Safari.

I too get the same 405 Method not allowed in Firefox. Here is my script:

function vote_for_synonym(word1, word2){
word1 = encodeURIComponent(word1);
word2 = encodeURIComponent(word2);

$req = new Ajax.Request("http://spreadsheets.google.com/formResponse?formkey=dFpVLTVFY2t5dWdoNTZpNERwWDRxX2c6MQ", {
  method: 'post',
  contentType: 'application/x-www-form-urlencoded',
  onCreate: function(){
   Element.show('systemWorking');
  },
  onSuccess: function() {
    Element.show('thanks');
    Element.hide('systemWorking')
  },
  onFailure: function() {
    Element.show('error');
  }
});           

}

Also, my onFailure never gets called, just onSuccess.

Eric Pugh
A: 

To resolve the 405 issue with firefox, use libcurl. Should be able to do so in Php and Python.

razorsniper