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" } )
it still doesn’t work .
never mind i got it now
But I have another problem . I get the error message but the information still gets sent to the database . For example if I put in a username and click register the username field gets filled in but the other fields are empty
You are going to need to share some updated code
local composer = require( "composer" ) local scene = composer.newScene() local widget = require("widget") -- forward declare the text fields local json = require("json") local username local password local email local function emptyFields( event ) if ( username.text == "" or password.text == "" or password2.text == "" or email.text == "" ) then local alert = native.showAlert( "Error", "Fill in all fields .", { "Try again" } ) 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 if emptyFields() == true then else 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 end local function loginLink( event ) if ( "ended" == event.phase ) then composer.gotoScene("login") end end function scene:create(event) local screenGroup = self.view display.setDefault("background", 0, 3, 5) local icon = display.newImage("hash\_opt.png", 160, 70) screenGroup:insert(icon) local myText = display.newText( "#Hash", 160, 150, native.systemFontBold, 26 ) myText:setFillColor( 1, 2, 4.5 ) username = native.newTextField( 160, 200, 180, 30 ) -- take the local off since it's forward declared username.placeholder = "Username" screenGroup:insert(username) password = native.newTextField( 160, 250,180, 30 ) -- take the local off since it's forward declared password.isSecure = true password.placeholder = "Password" screenGroup:insert(password) password2 = native.newTextField( 160, 300,180, 30 ) -- take the local off since it's forward declared password2.isSecure = true password2.placeholder = "Confirm Password" screenGroup:insert(password2) email = native.newTextField( 160, 350, 180, 30 ) -- take the local off since it's forward declared email.placeholder = "E-mail" screenGroup:insert(email) local Button = widget.newButton( { shape = "roundedRect", left = 70, top = 400, id = "Register", label = "Register", onEvent = userRegister } ) screenGroup:insert(Button) local Button2 = widget.newButton( { left = 70, top = 460, id = "Loginhere", label = "Login here", onEvent = loginLink } ) screenGroup:insert(Button2) end function scene:show(event) end function scene:hide(event) end function scene:destroy(event) end scene:addEventListener("create", scene) scene:addEventListener("show", scene) scene:addEventListener("hide", scene) scene:addEventListener("destroy", scene) return scene
Empty fields is not returning anything.
But it’s showing the native.showAlert
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 ) return true else return false end end