3

The form is multipaged, like this and I tried to use POST request, but it works only for one-paged form, check this subject. Maybe there are another ways?

Askarovich
  • 59
  • 1
  • 7

2 Answers2

5

Try this code.

WebClient client = new WebClient();
var nameValue = new NameValueCollection();
nameValue.Add("entry.xxx", "VALUE");// You will find these in name (not id) attributes of the input tags 
nameValue.Add("entry.xxx", "VALUE");
nameValue.Add("entry.xxx", "VALUE");
nameValue.Add("entry.xxx", "VALUE");
nameValue.Add("pageHistory", "0,1,2");//Comma separated page indexes
Uri uri = new Uri("https://docs.google.com/forms/d/e/[FORM_ID]/formResponse");
byte[] response = client.UploadValues(uri, "POST", nameValue);
string result = Encoding.UTF8.GetString(response);

I tried this with 3 pages. You can have any number of pages "i guess". This will submit the data directly and return "Success page from google forms".

EDIT

I Have not worked with google forms "like never", so was not able to find a proper way to do this if there is any, but this seems to work just fine.

Append this to your uri for multiple checkboxes

?entry.xxxx=Option+1&entry.xxxx=Option2 

entry.xxxx remains same for one question if you have multiple questions with check boxes then it would change to this

?entry.xxx=Option+1&entry.xxx=Option2&entry.zzz=Option+1&entry.zzz=Option2

value is the lable of your check box replace (whitespace) with (+) plus if any like in (Option 1)

1

Puneet's answer was the only answer I've found on how to deal with checkboxes with multiple values. I tried to find a way to put multiple checkbox values in the body of the response instead of in the URL but could not.

In the spirit of his answer, I've made a GoogleFormSubmissionService in C# to make dealing with Google Forms easy in C#.

You can find it on my Gist here: Google Forms Submission Service in C#

Zodman
  • 3,178
  • 2
  • 32
  • 38