How to send input field text over the wwwforms

Hi all,

Iam trying to get the value of an input field but I am getting erros. Hope you guys can help me:

I have the following code on my script:

function connect_www(){

   var value = GameObject.Find("login").GetComponent(Text).text;
   
   Debug.Log("Valor: "+valor);
 
   var form = new WWWForm();
    
   form.AddField( "login", login);

}

When I run I get the following error:

Object reference not set to an instance of an object
main.connect_www() (at Assets/main.js:16)

I have a button on the screen that when it is clicked runs this function. I also have an input field that has the name “login”.

just a thought but “GetComponent(Text)” looks like it would be wrong, dont you want to do GetComponent(InputField)

Just noticed that. I changed but same error.

Hi,
I think you could change:

function connect_www() {

    var value = GameObject.Find("login").GetComponent(InputField).text;

    Debug.Log("Valor: " + value);
    //Debug.Log("Valor: " + valor);

    var form = new WWWForm();

    form.AddField("login", value);
    //form.AddField("login", login);
}

You’re using undefined variables in your code.

Espero que ajude!

1 Like