1

I'm trying to auto-fill a google form via POST. However when I actually POST the data to it, only the first pages questions actually get filled.

Example Code:

    private static void PostToFormTest()
    {
        WebClient client = new WebClient();
        var keyValue = new NameValueCollection();
        keyValue.Add("entry.843521592", "Option 1");
        keyValue.Add("entry.901429584", "Test Right Now");
        keyValue.Add("entry.347619935", "Test Page 2");
        Uri uri = new Uri("https://docs.google.com/forms/d/1zuQxyoRUQ-jYwTf7wrPu9Wqln8ec7gfhzRbOILD3LGU/formResponse");
        byte[] response = client.UploadValues(uri, "POST", keyValue);
        string result = Encoding.UTF8.GetString(response);

    }

Responses Sheet:

https://docs.google.com/spreadsheets/d/1B4OSjQRQ37Q5Dt4mxMAx0wx5LfyajvWf_5rCY4lOvBU/edit?usp=sharing

Form:

https://docs.google.com/forms/d/1zuQxyoRUQ-jYwTf7wrPu9Wqln8ec7gfhzRbOILD3LGU/viewform

Douglas Gaskell
  • 9,017
  • 9
  • 71
  • 128

3 Answers3

3

Add this key in your NameValueCollection.

keyValue.Add("pageHistory", "0,1,2");//Comma separated page indexes (this is for 3 pages`enter code here`)
1

You are posting to a URL that only has 2 of the key value pairs:

// On page #1.
keyValue.Add("entry.843521592", "Option 1");
keyValue.Add("entry.901429584", "Test Right Now");

// On page #2.
keyValue.Add("entry.347619935", "Test Page 2");

The value for the second page cannot be added as the question does not exist when you post to the first page.

Karl Gjertsen
  • 4,690
  • 8
  • 41
  • 64
  • In short, there is no way to post to a multi-page form? – Douglas Gaskell Nov 23 '15 at 08:38
  • I don't think you can by using Google forms. I looked in to this previously. I know that Infiniforms (www.Infiniforms.io) are planning to add similar functionality to their forms soon. – Karl Gjertsen Nov 23 '15 at 08:40
  • Gotcha. Grasping at straws here, but I noticed a field named `fbzx` that populates after you go past the first page, does this field have anything to do with stored data on your "session"? I also noticed that `pageHistory` populates as you go through the pages as well. – Douglas Gaskell Nov 23 '15 at 08:45
  • I played with several attempts for a while and couldn't get anything to work. The answers I could find didn't help me much either. Sorry. – Karl Gjertsen Nov 23 '15 at 08:47
  • Thanks, I'll keep digging for a bit, if I find an answer I will post it here. Otherwise I will mark yours as the answer. – Douglas Gaskell Nov 23 '15 at 08:48
  • Thanks. It would be interesting to hear what you find. – Karl Gjertsen Nov 23 '15 at 08:49
0

capture all the "entry.#" and then don't foget the pageHistory with total number of pages starting from 0 (like Puneet pointed out)