TextField as variable in HTTP POST

Hi,

I’ve a problem with sending params via HTTP POST. In my app I have to send 2 params: “hash” and content of textField. When I try to send the params I get error information saying that text is a nil value. I tried create variable e.g. “local pole = txtFirstName.text”, but it isn’t working too.

I paste the most importatne parts of my code:

local imei = system.getInfo( "deviceID" ) local hashe = crypto.digest( crypto.md5, imei ) if imei then print(hashe) end txtFirstName = native.newTextField( 237, 170,400, 130 ) txtFirstName.size = 30 txtFirstName:addEventListener( "userInput", txtFirstName ) local params = {} params.body = "tresc="..txtFirstName.text.."&hash=hashe" local function networkListener( event ) if ( event.isError ) then print( "Network error!") else print ( "RESPONSE: " .. event.response ) end end function wysylanie (event) if event.phase == "began" then storyboard.gotoScene("udano", "fade", 500) network.request( "localhost/send.php", "POST", networkListener, params) end end

Thanks a lot for help :wink:

Keep in mind that Corona is event-driven.  So when the following code executes:

        params.body = “tresc=”…txtFirstName.text…"&hash=hashe"
the value of txtFirstName.text is nil … the user hasn’t had any chance to put input into the field yet.

I think if you move that code into the wysylanie function, it should work (assuming the user had entered text before attempting the network request).  Then you wouldn’t be referring to txtFirstName.text until some other events had happened (you probably still want to check for nil).

Keep in mind that Corona is event-driven.  So when the following code executes:

        params.body = “tresc=”…txtFirstName.text…"&hash=hashe"
the value of txtFirstName.text is nil … the user hasn’t had any chance to put input into the field yet.

I think if you move that code into the wysylanie function, it should work (assuming the user had entered text before attempting the network request).  Then you wouldn’t be referring to txtFirstName.text until some other events had happened (you probably still want to check for nil).