I am working on automating a consent/sign-in Google Form utilizing our campus CAS system by creating a front end for the Google Form in order to allow admins to still keep all the analytics given by google from the google sheet it uses.
I am currently using the WebClient approach below and have had success with getting every field submit successfully through the POST request except the responses from a multi-select checkbox. When I try to send anything that does not match a response on my google form EX: Google Form has checkbox with value "Other" and I try and send a parameter containing the value "Other X1231" the client.UploadValues fails. Following this I am unable to send no more than one value from the checkbox which defeats the purpose of having a multiple-select checkbox. My current approach is utilizing info from this question How to post data to specific URL using WebClient in C#
EDIT: After further investigation I was able to get the prefilled link google uses and I was able to see what the URL looks like with checkbox values. Here it is. As you can see there are infact multiple entry.33031323's being sent. I found out that NameValueCollections do not allow duplicate keys which is what I need to do in order for this to work as far as I can see.
using (WebClient client = new WebClient())
{
var reqparm = new System.Collections.Specialized.NameValueCollection();
reqparm.Add("entry.2041020761", consentText);
reqparm.Add("entry.1441757426", participantFullName.Text);
reqparm.Add("entry.1952327001", wNumber.Text);
reqparm.Add("entry.112478472", demographicDD.SelectedValue.ToString());
reqparm.Add("entry.1683121781", classLocationDD.SelectedValue.ToString());
reqparm.Add("entry.745164965", classTypeDD.SelectedValue.ToString());
reqparm.Add("entry.1194649100", classTimeDD.SelectedValue.ToString());
reqparm.Add("entry.33031323", "Word-of-Mouth");
reqparm.Add("entry.33031323", "Other");
byte[] responsebytes = client.UploadValues("https://docs.google.com/forms/u/0/d/e/1FAIpQLScojrZli-0eNGABtqHUmoClqu14R07lhcwkn6ZaHXB0t5wS0g/formResponse", "POST", reqparm);
string responsebody = Encoding.UTF8.GetString(responsebytes);
}
entry.XXXX corresponds to fields on the google form. If I run the code above with two
reqparm.Add("entry.33031323", "Other");
the result I get is pictured below.
However, if I just have one entry.33031323 like the following the form is accepted and recorded on the Google Sheet connected to the Google Form pictured below.
using (WebClient client = new WebClient())
{
var reqparm = new System.Collections.Specialized.NameValueCollection();
reqparm.Add("entry.2041020761", consentText);
reqparm.Add("entry.1441757426", participantFullName.Text);
reqparm.Add("entry.1952327001", wNumber.Text);
reqparm.Add("entry.112478472", demographicDD.SelectedValue.ToString());
reqparm.Add("entry.1683121781", classLocationDD.SelectedValue.ToString());
reqparm.Add("entry.745164965", classTypeDD.SelectedValue.ToString());
reqparm.Add("entry.1194649100", classTimeDD.SelectedValue.ToString());
reqparm.Add("entry.33031323", "Word-of-Mouth");
byte[] responsebytes = client.UploadValues("https://docs.google.com/forms/u/0/d/e/1FAIpQLScojrZli-0eNGABtqHUmoClqu14R07lhcwkn6ZaHXB0t5wS0g/formResponse", "POST", reqparm);
string responsebody = Encoding.UTF8.GetString(responsebytes);
}
I am able to get all the items from the checkbox through looping through/LINQ, however if I try and send that string of responses to entry.33031323 it throws the same error EX: "Word-of-Mouth Other Website" != any response on the form like "Website". How can I make this all work?
This is my CheckBoxList control
How did you hear about the GroupX program? (Optional)
<asp:CheckBoxList ID="howDidYouHearAboutUsCBL" runat="server">
<asp:ListItem Text="Social Media" Value="Social Media"></asp:ListItem>
<asp:ListItem Text="Website" Value="Website"></asp:ListItem>
<asp:ListItem Text="Word-of-Mouth" Value="Word-of-Mouth"></asp:ListItem>
<asp:ListItem Text="Print Media" Value="Print Media"></asp:ListItem>
<asp:ListItem Text="Other" Value="Other"></asp:ListItem>
</asp:CheckBoxList>
This is the checkbox group on the Google Form i'm using to test.