Jump to content

[HELP] getGuiText()=="" not working


..:D&G:..

Recommended Posts

Hello guys, I tried to make a form as a GUI, but when I use "getGuiText(guiElement)=="" " to see if the player has entered something for all the fields, it just send the form as if the player did enter everything, which he didn't...

function sendCVData(button, state) 
    if (source==bSend) and (button=="left") and (state=="up") then 
        if (guiGetText(mName) == "") or (guiGetText(mAge) == "") or (guiGetText(mPhone) == "") or (guiGetText(mAddress) == "") or (guiGetText(mQuestion) == "") or (guiGetText(mEducation) == "") or (guiGetText(mBio) == "") or (guiGetText(mHoursPlayed) == "") or (guiGetText(mOOCAge) == "") or (guiGetText(mFaction) == "") or (guiGetText(mRPLvl) == "") then 
            outputChatBox("Please enter all the details needed.", 255, 0, 0) 
        elseif not tonumber(guiGetText(mPhone)) then 
            outputChatBox("The phone number doesn't seem to be valid.", 255, 0, 0) 
        elseif not tonumber(guiGetText(mOOCAge)) or not tonumber(guiGetText(mAge)) then 
            outputChatBox("Your age doesn't seem to be valid", 255, 0, 0) 
        else 
            outputChatBox(guiGetText(mAge)) 
            local name = guiGetText(mName) 
            triggerServerEvent("saveCVData", resourceRoot, getLocalPlayer(), name, guiGetText(mAge), guiGetText(mPhone), guiGetText(mAddress), guiGetText(mQuestion), guiGetText(mEducation), guiGetText(mBio), guiGetText(mHoursPlayed), guiGetText(mOOCAge), guiGetText(mFaction), guiGetText(mRPLvl), cvPedName, factionName) 
        --  destroyElement(formWindow) 
        --  formWindow = nil 
        --  showCursor(false) 
        --  guiSetInputEnabled(false) 
        end 
    end 
end 

Any ideas?

Thanks.

Link to comment
if not (guiGetText(mName) == "") 

If there has to be something there you gotta check that the text doesn't equal "" what actually means nothing.

Well this is the gui element:

mAge = guiCreateMemo(129, 113, 43, 35, "", false, formWindow) 

And it has "" as a text ,which is just empty, so it should work with "== "" " so it should work.

EDIT -

Now I added "if not" and "or not" and now it keeps saying "enter all the information" even if I did.

Link to comment
local edits = {mName,mAge,mPhone,mAddress,mQuestion,mEducation,mBio,mHoursPlayed,mOOCAge,mFaction,mRPLvl} 
  
function sendCVData(button, state) 
    if (source==bSend) and (button=="left") and (state=="up") then 
        for k,v in ipairs(edits) do 
            if #guiGetText(v) == 0 then 
                outputChatBox("Please enter all the details needed.", 255, 0, 0) 
                return false 
            end 
        end 
        if not tonumber(guiGetText(mPhone)) then 
            outputChatBox("The phone number doesn't seem to be valid.", 255, 0, 0) 
        elseif not tonumber(guiGetText(mOOCAge)) or not tonumber(guiGetText(mAge)) then 
            outputChatBox("Your age doesn't seem to be valid", 255, 0, 0) 
        else 
            outputChatBox(guiGetText(mAge)) 
            local name = guiGetText(mName) 
            triggerServerEvent("saveCVData", resourceRoot, getLocalPlayer(), name, guiGetText(mAge), guiGetText(mPhone), guiGetText(mAddress), guiGetText(mQuestion), guiGetText(mEducation), guiGetText(mBio), guiGetText(mHoursPlayed), guiGetText(mOOCAge), guiGetText(mFaction), guiGetText(mRPLvl), cvPedName, factionName) 
        --  destroyElement(formWindow) 
        --  formWindow = nil 
        --  showCursor(false) 
        --  guiSetInputEnabled(false) 
        end 
    end 
end 

Link to comment
local edits = {mName,mAge,mPhone,mAddress,mQuestion,mEducation,mBio,mHoursPlayed,mOOCAge,mFaction,mRPLvl} 
  
function sendCVData(button, state) 
    if (source==bSend) and (button=="left") and (state=="up") then 
        for k,v in ipairs(edits) do 
            if #guiGetText(v) == 0 then 
                outputChatBox("Please enter all the details needed.", 255, 0, 0) 
                return false 
            end 
        end 
        if not tonumber(guiGetText(mPhone)) then 
            outputChatBox("The phone number doesn't seem to be valid.", 255, 0, 0) 
        elseif not tonumber(guiGetText(mOOCAge)) or not tonumber(guiGetText(mAge)) then 
            outputChatBox("Your age doesn't seem to be valid", 255, 0, 0) 
        else 
            outputChatBox(guiGetText(mAge)) 
            local name = guiGetText(mName) 
            triggerServerEvent("saveCVData", resourceRoot, getLocalPlayer(), name, guiGetText(mAge), guiGetText(mPhone), guiGetText(mAddress), guiGetText(mQuestion), guiGetText(mEducation), guiGetText(mBio), guiGetText(mHoursPlayed), guiGetText(mOOCAge), guiGetText(mFaction), guiGetText(mRPLvl), cvPedName, factionName) 
        --  destroyElement(formWindow) 
        --  formWindow = nil 
        --  showCursor(false) 
        --  guiSetInputEnabled(false) 
        end 
    end 
end 

It must be one because guiGetText starts counting by 1.

if #guiGetText(v) == 1 then 
     outputChatBox("Please enter all the details needed.", 255, 0, 0) 
     return false 
end 

Link to comment
local edits = {mName,mAge,mPhone,mAddress,mQuestion,mEducation,mBio,mHoursPlayed,mOOCAge,mFaction,mRPLvl} 
  
function sendCVData(button, state) 
    if (source==bSend) and (button=="left") and (state=="up") then 
        for k,v in ipairs(edits) do 
            if #guiGetText(v) == 0 then 
                outputChatBox("Please enter all the details needed.", 255, 0, 0) 
                return false 
            end 
        end 
        if not tonumber(guiGetText(mPhone)) then 
            outputChatBox("The phone number doesn't seem to be valid.", 255, 0, 0) 
        elseif not tonumber(guiGetText(mOOCAge)) or not tonumber(guiGetText(mAge)) then 
            outputChatBox("Your age doesn't seem to be valid", 255, 0, 0) 
        else 
            outputChatBox(guiGetText(mAge)) 
            local name = guiGetText(mName) 
            triggerServerEvent("saveCVData", resourceRoot, getLocalPlayer(), name, guiGetText(mAge), guiGetText(mPhone), guiGetText(mAddress), guiGetText(mQuestion), guiGetText(mEducation), guiGetText(mBio), guiGetText(mHoursPlayed), guiGetText(mOOCAge), guiGetText(mFaction), guiGetText(mRPLvl), cvPedName, factionName) 
        --  destroyElement(formWindow) 
        --  formWindow = nil 
        --  showCursor(false) 
        --  guiSetInputEnabled(false) 
        end 
    end 
end 

It still goes to the triggerServerEvent when 1 or more fields are empty, which should be triggered when all the fields have some text it them...

Link to comment

[quote name=..:D&G:..]

local edits = {mName,mAge,mPhone,mAddress,mQuestion,mEducation,mBio,mHoursPlayed,mOOCAge,mFaction,mRPLvl} 
  
function sendCVData(button, state) 
    if (source==bSend) and (button=="left") and (state=="up") then 
        for k,v in ipairs(edits) do 
            if #guiGetText(v) == 0 then 
                outputChatBox("Please enter all the details needed.", 255, 0, 0) 
                return false 
            end 
        end 
        if not tonumber(guiGetText(mPhone)) then 
            outputChatBox("The phone number doesn't seem to be valid.", 255, 0, 0) 
        elseif not tonumber(guiGetText(mOOCAge)) or not tonumber(guiGetText(mAge)) then 
            outputChatBox("Your age doesn't seem to be valid", 255, 0, 0) 
        else 
            outputChatBox(guiGetText(mAge)) 
            local name = guiGetText(mName) 
            triggerServerEvent("saveCVData", resourceRoot, getLocalPlayer(), name, guiGetText(mAge), guiGetText(mPhone), guiGetText(mAddress), guiGetText(mQuestion), guiGetText(mEducation), guiGetText(mBio), guiGetText(mHoursPlayed), guiGetText(mOOCAge), guiGetText(mFaction), guiGetText(mRPLvl), cvPedName, factionName) 
        --  destroyElement(formWindow) 
        --  formWindow = nil 
        --  showCursor(false) 
        --  guiSetInputEnabled(false) 
        end 
    end 
end 

It still goes to the triggerServerEvent when 1 or more fields are empty, which should be triggered when all the fields have some text it them...

Try that

  
        for k,v in ipairs(edits) do 
            if #guiGetText(v) == 0 then 
                outputChatBox("Please enter all the details needed.", 255, 0, 0) 
                break 
            end 
        end 
  

Link to comment
[quote name=..:D&G:..]
local edits = {mName,mAge,mPhone,mAddress,mQuestion,mEducation,mBio,mHoursPlayed,mOOCAge,mFaction,mRPLvl} 
  
function sendCVData(button, state) 
    if (source==bSend) and (button=="left") and (state=="up") then 
        for k,v in ipairs(edits) do 
            if #guiGetText(v) == 0 then 
                outputChatBox("Please enter all the details needed.", 255, 0, 0) 
                return false 
            end 
        end 
        if not tonumber(guiGetText(mPhone)) then 
            outputChatBox("The phone number doesn't seem to be valid.", 255, 0, 0) 
        elseif not tonumber(guiGetText(mOOCAge)) or not tonumber(guiGetText(mAge)) then 
            outputChatBox("Your age doesn't seem to be valid", 255, 0, 0) 
        else 
            outputChatBox(guiGetText(mAge)) 
            local name = guiGetText(mName) 
            triggerServerEvent("saveCVData", resourceRoot, getLocalPlayer(), name, guiGetText(mAge), guiGetText(mPhone), guiGetText(mAddress), guiGetText(mQuestion), guiGetText(mEducation), guiGetText(mBio), guiGetText(mHoursPlayed), guiGetText(mOOCAge), guiGetText(mFaction), guiGetText(mRPLvl), cvPedName, factionName) 
        --  destroyElement(formWindow) 
        --  formWindow = nil 
        --  showCursor(false) 
        --  guiSetInputEnabled(false) 
        end 
    end 
end 

It still goes to the triggerServerEvent when 1 or more fields are empty, which should be triggered when all the fields have some text it them...

Try that

  
        for k,v in ipairs(edits) do 
            if #guiGetText(v) == 0 then 
                outputChatBox("Please enter all the details needed.", 255, 0, 0) 
                break 
            end 
        end 
  

break gonna stop the loop only

Link to comment

It just doesn't work, here is the GUI, maybe it will help:

function showCVFormWindow(factionName, cvPedName) 
    local width, height = 402, 855 
    local scrWidth, scrHeight = guiGetScreenSize() 
    local x = scrWidth/2 - (width/2) 
    local y = scrHeight/2 - (height/2) 
     
    if not (isElement(formWindow)) then 
        formWindow = guiCreateWindow(x, y, width, height, "Formular CV - "..factionName, false) 
        guiWindowSetSizable(formWindow, false) 
  
        lName = guiCreateLabel(63, 82, 39, 18, "Name:", false, formWindow) 
        mName = guiCreateMemo(129, 106, 150, 31, getPlayerName(getLocalPlayer()), false, formWindow) 
        guiMemoSetReadOnly(mName, true) 
        lAge = guiCreateLabel(64, 123, 48, 15, "Age:", false, formWindow) 
        mAge = guiCreateMemo(129, 113, 43, 35, "", false, formWindow) 
        lPhone = guiCreateLabel(63, 158, 64, 18, "Telephone:", false, formWindow) 
        mPhone = guiCreateMemo(129, 155, 150, 31, "", false, formWindow) 
        lAddress = guiCreateLabel(65, 206, 54, 15, "Address:", false, formWindow) 
        mAddress = guiCreateMemo(129, 196, 150, 51, "", false, formWindow) 
        lQuestion = guiCreateLabel(120, 405, 159, 17, "Why do you want to join us?", false, formWindow) 
        mQuestion = guiCreateMemo(43, 432, 313, 91, "", false, formWindow) 
        lEducation = guiCreateLabel(63, 262, 41, 21, "Education:", false, formWindow) 
        mEducation = guiCreateMemo(127, 256, 150, 32, "", false, formWindow) 
        lBio = guiCreateLabel(168, 293, 67, 16, "Short Bio", false, formWindow) 
        mBio = guiCreateMemo(43, 314, 313, 77, "", false, formWindow) 
        gShow1 = guiCreateGridList(119, 529, 154, 37, false, formWindow) 
  
        lOOC = guiCreateLabel(45, 10, 65, 17, "OOC", false, gShow1) 
  
        lHoursPlayed = guiCreateLabel(41, 576, 63, 17, "Hours Played:", false, formWindow) 
        mHoursPlayed = guiCreateMemo(106, 572, 54, 31, getElementData(getLocalPlayer(), "hoursplayed") or 0, false, formWindow) 
        guiMemoSetReadOnly(mHoursPlayed, true) 
        lOOCAge = guiCreateLabel(238, 582, 40, 14, "Age:", false, formWindow) 
        mOOCAge = guiCreateMemo(283, 575, 44, 31, "", false, formWindow) 
        lFaction = guiCreateLabel(137, 613, 116, 15, "Last Factions", false, formWindow) 
  
        mFaction = guiCreateMemo(99, 638, 194, 33, "", false, formWindow) 
        lRPLvl = guiCreateLabel(107, 681, 186, 17, "Roleplay skills?(1 la 10)", false, formWindow) 
        mRPLvl = guiCreateMemo(174, 708, 54, 36, "", false, formWindow) 
        gShow2 = guiCreateGridList(125, 22, 154, 37, false, formWindow) 
  
        lIC = guiCreateLabel(52, 11, 49, 16, "IC", false, gShow2) 
  
        bClose = guiCreateButton(327, 764, 63, 30, "Close", false, formWindow) 
        addEventHandler("onClientGUIClick", bClose, closeCVFormWindow) 
        guiSetProperty(bClose, "NormalTextColour", "FFFE0000") 
        bSend = guiCreateButton(135, 754, 128, 55, "Send Form", false, formWindow) 
        addEventHandler("onClientGUIClick", bSend, sendCVData) 
        guiSetFont(bSend, "default-bold-small") 
        guiSetProperty(bSend, "NormalTextColour", "FF00FE18")     
        showCursor(true) 
        guiSetInputEnabled(true) 
    end 
end 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...