Check for empty fields

I am trying to run this function to check if the username password or email fields are empty , but it’s not running how I want it to . 

local function emptyFields( event ) if ( "username", "password", "email" == 0 ) then native.showAlert() end end -- Show alert with two buttons local alert = native.showAlert( "Please fill in all fields .", emptyFields )

I am getting this error : ERROR: C:\Users\user\Documents\Corona Projects\app\register.lua:39: native.s

howAlert() called with unexpected parameters

It should look like this

local function emptyFields( event ) if ( username == "" or password == "" or email == "" ) then local alert = native.showAlert( "Please fill in all fields .", emptyFields ) end end

I you are using text fields or box you may need to do this

local function emptyFields( event ) if ( username.text == "" or password.text == "" or email.text == "" ) then local alert = native.showAlert( "Please fill in all fields .", emptyFields ) end end

I am guessing emptyFields is a string value?

Please read docs for more info

https://docs.coronalabs.com/api/library/native/showAlert.html

I’m not getting any errors but it’s not showing anything 

Can you share some code?

local function emptyFields( event ) if ( username.text == "" or password.text == "" or password2 == "" or email.text == "" ) then local alert = native.showAlert( "Please fill in all fields .", emptyFields ) end end local function urlencode(str) if (str) then str = string.gsub (str, "\n", "\r\n") str = string.gsub (str, "([^%w])", function (c) return string.format ("%%%02X", string.byte(c)) end) str = string.gsub (str, " ", "+") end return str end local function networkListener( event ) if ( event.isError ) then print( "Network error. ") else if event.response == "success" then print("Success! We are now registered!") -- put the code here to go to where the user needs to be -- after a successful registration composer.gotoScene("login") else -- put code here to notify the user of the problem, perhaps -- a native.alert() dialog that shows them the value of event.response -- and take them back to the registration screen to let them try again end end end local function userRegister( event ) if ( "ended" == event.phase ) then local URL = "http://hash.comxa.com/register.php?Register=1&username=" .. username.text .. "&password=" .. password.text .. "&password2=" .. password2.text .. "&email=" .. urlencode( email.text ) network.request(URL, "GET", networkListener) end end

That’s the order that I have it in

Are username, password; and email text fields. What is emptyFields?

Their text fields 

Oh I see you need to replace local alert = native.showAlert( “Please fill in all fields .”, emptyFields ) with this local alert = native.showAlert( “Please fill in all fields .”, “message here” ) Also is emptyFields being called?

No I don’t know where to call it

I would do this

Would not format right
https://docs.google.com/document/d/11LNItMsWY4msOT7TalH7wGZMeZKPvh2VOCBfVJ4tMlI

can you pit it in code brackets ? 

Sorry I am on mobile, no code brackets. I just made a word docs really quick

 C:\Users\user\Documents\Corona Projects\app\register.lua:56: '\<name\> ' expected near '/' 

I am getting this error 

Try this url local URL = “http://hash.comxa.com/register.php?Register=1&username=” … username.text … “&password=” … password.text … “&password2=” … password2.text … “&email=” … urlencode( email.text )

Now i’m not getting an error : ERROR: C:\Users\user\Documents\Corona Projects\app\register.lua:15: native.s

howAlert() called with unexpected parameters

local alert = native.showAlert( "Please fill in all fields .", emptyFields )

Can anybody help ?

You have to have a message which is a string

native.showAlert( title, message [, buttonLabels [, listener] ] )

emptyFields is not a string it is a function

Also your if statement:

if ( username.text == "" or password.text == "" or password2 == "" or email.text == "" ) then

will always evaluate to true since password2 exists. I think what you want here is:

if ( username.text == “” or password.text == “” or password2_ .text _ == “” or email.text == “” ) then

Then for your native.showAlert() it needs to be something like:

local alert = native.showAlert( "Warning", "Please fill in all fields .", { "Ok" }&nbsp; )

it still doesn’t work . 

never mind i got it now