0

How can I add value on the other section on Google forms in unity3d?

I can only add values on section 1. I am having trouble on adding values on other sections.

enter image description here

here is the code

public GameObject username;
public GameObject email;
public GameObject phone;
public GameObject phone2;

private string Name;
private string Email;
private string Phone;
private string Phone2;

[SerializeField]
private string BASE_URL = "https://docs.google.com/forms/d/e/1FAIpQLSc8rwjEYJ0akVuuRo0GULsoyhvBxgLwuvv6oDtWiJgJZjyiMw/formResponse";

IEnumerator Post(string name, string email, string phone, string phone2) {
    WWWForm form = new WWWForm();

    form.AddField("entry.1417744726", name);
    form.AddField("entry.881581736", email);
    form.AddField("entry.977000887", phone);
    form.AddField("entry.1897661126", phone2);

    byte[] rawData = form.data;
    WWW www = new WWW(BASE_URL, rawData);
    yield return www;
}
public void Send() {
    Name = username.GetComponent<InputField>().text;
    Email = email.GetComponent<InputField>().text;
    Phone = phone.GetComponent<InputField>().text;
    Phone2 = phone2.GetComponent<InputField>().text;
    StartCoroutine(Post(Name, Email, Phone, Phone2));

}
Ludovic Feltz
  • 11,416
  • 4
  • 47
  • 63
  • What did you try? Can you post some code? – Ludovic Feltz Sep 03 '19 at 08:30
  • I already edited the question and add the script. – iamDonMokong Sep 03 '19 at 08:38
  • what exactly is the question? Is this about the google docs API or is something unclear how to send the request using Unity? In general I would suggest to rather use [`UnityWebRequest.Post`](https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequest.Post.html) instead of [`WWW`](https://docs.unity3d.com/ScriptReference/WWW.html) (which is obsolete) – derHugo Sep 03 '19 at 14:32
  • I have 2 sections in google forms. I can only add value on the first section. as seen on the picture. My problem is that i cant add value on the 2nd section in google forms. – iamDonMokong Sep 03 '19 at 14:38

1 Answers1

0

Unfortunately, it seems that this method of posting info to google forms is unreliable, as it's not well documented at all progress here is from looking at the html page code. I've followed the same tutorial and also having trouble.

But fortunately, I've found a better solution that gives you better control and access to google forms.

https://developers.google.com/apps-script/

https://developers.google.com/apps-script/reference/forms/

Instead of guessing the post API, using Google Apps Script, you can setup and deploy a web app from googles own servers in javascript, and interface with forms directly. From there you just have to design JSON payload. I got it working already using Postman to simulate the web request that will be sent from unity.

In terms of the section issue your facing, in the google apps script javascript thats not too much an issue, as the sections are just used to visually break the front end up and they don't affect the data. However they are represented as an "item" in the backend, so when you are copying the answers from the JSON payload to the form responses be mindful which index your sections are so you can skip them and not accidentally loss data.