Jump to content

Validate my Input box before submit


 Share

Recommended Posts

Hi every one,

I am a noob and need your help. I have created this script

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <IE.au3>

Global $Form1 = GUICreate("My First App", 615, 550, 192, 124)
Global $Label1 = GUICtrlCreateLabel("Full Name:", 68, 40, 99, 29)
GUICtrlSetFont(-1, 16, 400, 0, "Myriad Hebrew")
Global $Label2 = GUICtrlCreateLabel("Email Address:", 32, 88, 133, 29)
GUICtrlSetFont(-1, 16, 400, 0, "Myriad Hebrew")
Global $Label3 = GUICtrlCreateLabel("Telephone:", 59, 133, 106, 29)
GUICtrlSetFont(-1, 16, 400, 0, "Myriad Hebrew")
Global $Label4 = GUICtrlCreateLabel("Ext:", 411, 133, 37, 29)
GUICtrlSetFont(-1, 16, 400, 0, "Myriad Hebrew")
Global $Label5 = GUICtrlCreateLabel("Help Topic:", 62, 182, 104, 29)
GUICtrlSetFont(-1, 16, 400, 0, "Myriad Hebrew")
Global $Label6 = GUICtrlCreateLabel("Subject:", 86, 230, 76, 29)
GUICtrlSetFont(-1, 16, 400, 0, "Myriad Hebrew")
Global $Label7 = GUICtrlCreateLabel("Message:", 75, 279, 87, 29)
GUICtrlSetFont(-1, 16, 400, 0, "Myriad Hebrew")
Global $Input1 = GUICtrlCreateInput ("", 176, 40, 209, 21)
Global $Input2 = GUICtrlCreateInput ("", 177, 86, 209, 21)
Global $Input3 = GUICtrlCreateInput ("", 177, 134, 209, 21, $ES_NUMBER)
     GUICtrlSetLimit(-1, 10)
Global $Input7 = GUICtrlCreateInput ("", 457, 134, 73, 21, $ES_NUMBER)
Global $Input4 = GUICtrlCreateCombo ("Please Select One", 177, 190, 209, 21)
     GUICtrlSetData  (-1, "Billing|Support") ;
Global $Input5 = GUICtrlCreateInput ("", 177, 238, 209, 21)
Global $Input6 = GuiCtrlCreateEdit ("", 177, 286, 409, 120)
Global $Button1 = GUICtrlCreateButton("Submit", 177, 424, 201, 49)

GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
Submit (GUICtrlRead($Input1), GUICtrlRead($Input2), GUICtrlRead($Input3), GUICtrlRead($Input4), GUICtrlRead($Input5), GUICtrlRead($Input6), GUICtrlRead($Input7))
EndSwitch
WEnd

Everything works fine just that even if I don't enter anything at all the user get no error message. I am hoping to be able to make all input require.

any help will be greatly appreciated thanks.

Link to comment
Share on other sites

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <IE.au3>

Global $Form1 = GUICreate("My First App", 615, 550, 192, 124)
Global $Label1 = GUICtrlCreateLabel("Full Name:", 68, 40, 99, 29)
GUICtrlSetFont(-1, 16, 400, 0, "Myriad Hebrew")
Global $Label2 = GUICtrlCreateLabel("Email Address:", 32, 88, 133, 29)
GUICtrlSetFont(-1, 16, 400, 0, "Myriad Hebrew")
Global $Label3 = GUICtrlCreateLabel("Telephone:", 59, 133, 106, 29)
GUICtrlSetFont(-1, 16, 400, 0, "Myriad Hebrew")
Global $Label4 = GUICtrlCreateLabel("Ext:", 411, 133, 37, 29)
GUICtrlSetFont(-1, 16, 400, 0, "Myriad Hebrew")
Global $Label5 = GUICtrlCreateLabel("Help Topic:", 62, 182, 104, 29)
GUICtrlSetFont(-1, 16, 400, 0, "Myriad Hebrew")
Global $Label6 = GUICtrlCreateLabel("Subject:", 86, 230, 76, 29)
GUICtrlSetFont(-1, 16, 400, 0, "Myriad Hebrew")
Global $Label7 = GUICtrlCreateLabel("Message:", 75, 279, 87, 29)
GUICtrlSetFont(-1, 16, 400, 0, "Myriad Hebrew")
Global $Input1 = GUICtrlCreateInput ("", 176, 40, 209, 21)
Global $Input2 = GUICtrlCreateInput ("", 177, 86, 209, 21)
Global $Input3 = GUICtrlCreateInput ("", 177, 134, 209, 21, $ES_NUMBER)
GUICtrlSetLimit(-1, 10)
Global $Input7 = GUICtrlCreateInput ("", 457, 134, 73, 21, $ES_NUMBER)
Global $Input4 = GUICtrlCreateCombo ("Please Select One", 177, 190, 209, 21)
GUICtrlSetData  (-1, "Billing|Support") ;
Global $Input5 = GUICtrlCreateInput ("", 177, 238, 209, 21)
Global $Input6 = GuiCtrlCreateEdit ("", 177, 286, 409, 120)
Global $Button1 = GUICtrlCreateButton("Submit", 177, 424, 201, 49)

GUISetState(@SW_SHOW)

While True
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $Name = GUICtrlRead($Input1)
            $Email = GUICtrlRead($Input2)
            $Phone = GUICtrlRead($Input3)
            $Help = GUICtrlRead($Input4)
            $Subject = GUICtrlRead($Input5)
            $Message = GUICtrlRead($Input6)
            $Ext = GUICtrlRead($Input7)
            If $Name And $Email And $Phone And $Ext And $Help And ($Help <> "Please Select One") And $Subject And $Message Then
                Submit($Name,$Email,$Phone,$Ext,$Help,$Subject,$Message)
            Else
                MsgBox(0x10,"Invalid input","All inputs are required.")
            EndIf
    EndSwitch
WEnd

When the words fail... music speaks.

Link to comment
Share on other sites

Easy Approach

GUICreate("My First App", 615, 550, 192, 124)

GUICtrlCreateLabel("Full Name:", 68, 40, 99, 29)
GUICtrlSetFont(-1, 16, 400, 0, "Myriad Hebrew")

GUICtrlCreateLabel("Email Address:", 32, 88, 153, 29)
GUICtrlSetFont(-1, 16, 400, 0, "Myriad Hebrew")

GUICtrlCreateLabel("Telephone:", 59, 133, 106, 29)
GUICtrlSetFont(-1, 16, 400, 0, "Myriad Hebrew")

GUICtrlCreateLabel("Ext:", 411, 133, 37, 29)
GUICtrlSetFont(-1, 16, 400, 0, "Myriad Hebrew")

GUICtrlCreateLabel("Help Topic:", 62, 182, 104, 29)
GUICtrlSetFont(-1, 16, 400, 0, "Myriad Hebrew")

GUICtrlCreateLabel("Subject:", 86, 230, 76, 29)
GUICtrlSetFont(-1, 16, 400, 0, "Myriad Hebrew")

GUICtrlCreateLabel("Message:", 75, 279, 87, 29)
GUICtrlSetFont(-1, 16, 400, 0, "Myriad Hebrew")

Global $Input = GUICtrlCreateInput ("", 176, 40, 209, 21)
GUICtrlCreateInput ("", 177, 86, 209, 21)

GUICtrlCreateInput ("", 177, 134, 209, 21, 8192) ;8192 = ES_NUMBER
GUICtrlCreateInput ("", 457, 134, 73, 21, 8192) ;8192 = ES_NUMBER

GUICtrlCreateCombo ("", 177, 190, 209, 21)
GUICtrlSetData  (-1, "Billing|Support") ;

GUICtrlCreateInput ("", 177, 238, 209, 21)
GuiCtrlCreateEdit ("", 177, 286, 409, 120)

Global $Button1 = GUICtrlCreateButton("Submit", 177, 424, 201, 49)

GUISetState(@SW_SHOW)

While True
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case -3
            Exit
        Case $Button1
            For $i = $Input To $Input + 6
                If GUICtrlRead($i) = '' Then ExitLoop GUICtrlSetState($i, 256) ;256 = GUI_FOCUS
            Next
            ;Submit()
    EndSwitch
WEnd
Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

Thank you both for your help but both scripts are given my errors.

@Andreik Even when I hit the submit button I still get All inputs are required even though all input are filled.

@PhoenixXL When I leave the input empty it will submit without any error message and run the function. Now when i fill in all inputs, the function does not run.

Link to comment
Share on other sites

since you didnt post your SUBMIT it becomes messy to make the code

you either post your total final code or try to reproduce a small example

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

OK sorry this is my entire code

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <IE.au3>


$Form1 = GUICreate("FantasyPC Submit Work Order", 615, 550, 192, 124)
$Label1 = GUICtrlCreateLabel("Full Name:", 68, 40, 99, 29)
GUICtrlSetFont(-1, 16, 400, 0, "Myriad Hebrew")
$Label2 = GUICtrlCreateLabel("Email Address:", 32, 88, 133, 29)
GUICtrlSetFont(-1, 16, 400, 0, "Myriad Hebrew")
$Label3 = GUICtrlCreateLabel("Telephone:", 59, 133, 106, 29)
GUICtrlSetFont(-1, 16, 400, 0, "Myriad Hebrew")
$Label4 = GUICtrlCreateLabel("Ext:", 411, 133, 37, 29)
GUICtrlSetFont(-1, 16, 400, 0, "Myriad Hebrew")
$Label5 = GUICtrlCreateLabel("Help Topic:", 62, 182, 104, 29)
GUICtrlSetFont(-1, 16, 400, 0, "Myriad Hebrew")
$Label6 = GUICtrlCreateLabel("Subject:", 86, 230, 76, 29)
GUICtrlSetFont(-1, 16, 400, 0, "Myriad Hebrew")
$Label7 = GUICtrlCreateLabel("Message:", 75, 279, 87, 29)
GUICtrlSetFont(-1, 16, 400, 0, "Myriad Hebrew")

$Input1 = GUICtrlCreateInput ("", 176, 40, 209, 21)
$Input2 = GUICtrlCreateInput ("", 177, 86, 209, 21)
$Input3 = GUICtrlCreateInput ("", 177, 134, 209, 21, $ES_NUMBER)
GUICtrlSetLimit(-1, 10)
$Input7 = GUICtrlCreateInput ("", 457, 134, 73, 21, $ES_NUMBER)
$Input4 = GUICtrlCreateCombo ("Please Select One", 177, 190, 209, 21)
GUICtrlSetData (-1, "Billing|Support") ;
$Input5 = GUICtrlCreateInput ("", 177, 238, 209, 21)
$Input6 = GuiCtrlCreateEdit ("", 177, 286, 409, 120)
$Button1 = GUICtrlCreateButton("Submit", 177, 424, 201, 49)


GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
Submit (GUICtrlRead($Input1), GUICtrlRead($Input2), GUICtrlRead($Input3), GUICtrlRead($Input4), GUICtrlRead($Input5), GUICtrlRead($Input6), GUICtrlRead($Input7))
EndSwitch
WEnd


Func Submit($Input1, $Input2, $Input3, $Input4, $Input5, $Input6, $Input7)

$oIE = _IECreate("http://www.fantasypc.com/support/open.php")
$oForm = _IEFormGetObjByName($oIE, "ticketForm")
$oSelect = _IEFormElementGetObjByName($oForm, "topicId")
$name = _IEFormElementGetObjByName($oForm, "name")
$email = _IEFormElementGetObjByName($oForm, "email")
$tel = _IEFormElementGetObjByName($oForm, "phone")
$tele = _IEFormElementGetObjByName($oForm, "phone_ext")
$top = _IEFormElementGetObjByName($oForm, "topicId")
$sub = _IEFormElementGetObjByName($oForm, "subject")
$mes = _IEFormElementGetObjByName($oForm, "message")

_IEFormElementSetValue ($name, $Input1)
_IEFormElementSetValue ($email, $Input2)
_IEFormElementSetValue ($tel, $Input3)
_IEFormElementOptionselect ($oSelect, $Input4, 1, "byText")
_IEFormElementSetValue ($sub, $Input5)
_IEFormElementSetValue ($mes, $Input6)
_IEFormElementSetValue ($tele, $Input7)
_IEFormSubmit ($oForm)

EndFunc
Edited by OrlandoAmador
Link to comment
Share on other sites

This is the Code you want

It stops the execution when a field is empty and submits when every field is entered

GUICreate("My First App", 615, 550, 192, 124)

GUICtrlCreateLabel("Full Name:", 68, 40, 99, 29)
GUICtrlSetFont(-1, 16, 400, 0, "Myriad Hebrew")

GUICtrlCreateLabel("Email Address:", 32, 88, 153, 29)
GUICtrlSetFont(-1, 16, 400, 0, "Myriad Hebrew")

GUICtrlCreateLabel("Telephone:", 59, 133, 106, 29)
GUICtrlSetFont(-1, 16, 400, 0, "Myriad Hebrew")

GUICtrlCreateLabel("Ext:", 411, 133, 37, 29)
GUICtrlSetFont(-1, 16, 400, 0, "Myriad Hebrew")

GUICtrlCreateLabel("Help Topic:", 62, 182, 104, 29)
GUICtrlSetFont(-1, 16, 400, 0, "Myriad Hebrew")

GUICtrlCreateLabel("Subject:", 86, 230, 76, 29)
GUICtrlSetFont(-1, 16, 400, 0, "Myriad Hebrew")

GUICtrlCreateLabel("Message:", 75, 279, 87, 29)
GUICtrlSetFont(-1, 16, 400, 0, "Myriad Hebrew")

Global $Input = GUICtrlCreateInput("", 176, 40, 209, 21)
GUICtrlCreateInput("", 177, 86, 209, 21)

GUICtrlCreateInput("", 177, 134, 209, 21, 8192) ;8192 = ES_NUMBER
GUICtrlCreateInput("", 457, 134, 73, 21, 8192) ;8192 = ES_NUMBER

GUICtrlCreateCombo("", 177, 190, 209, 21)
GUICtrlSetData(-1, "Billing|Support") ;

GUICtrlCreateInput("", 177, 238, 209, 21)
GUICtrlCreateEdit("", 177, 286, 409, 120)

Global $Button1 = GUICtrlCreateButton("Submit", 177, 424, 201, 49)

GUISetState(@SW_SHOW)

While True
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
Exit
Case $Button1
For $i = $Input To $Input + 6
If GUICtrlRead($i) = '' Then
GUICtrlSetState($i, 256)
ContinueLoop 2 ;256 = GUI_FOCUS
EndIf
Next
Submit($Input)
EndSwitch
WEnd

Func Submit($InputID)

$oIE = _IECreate("http://www.fantasypc.com/support/open.php")
$oForm = _IEFormGetObjByName($oIE, "ticketForm")
$oSelect = _IEFormElementGetObjByName($oForm, "topicId")
$name = _IEFormElementGetObjByName($oForm, "name")
$email = _IEFormElementGetObjByName($oForm, "email")
$tel = _IEFormElementGetObjByName($oForm, "phone")
$tele = _IEFormElementGetObjByName($oForm, "phone_ext")
$top = _IEFormElementGetObjByName($oForm, "topicId")
$sub = _IEFormElementGetObjByName($oForm, "subject")
$mes = _IEFormElementGetObjByName($oForm, "message")

_IEFormElementSetValue($name, GUICtrlRead($InputID))
_IEFormElementSetValue($email, GUICtrlRead($InputID + 1))
_IEFormElementSetValue($tel, GUICtrlRead($InputID + 2))
_IEFormElementOptionselect($oSelect, GUICtrlRead($InputID + 3), 1, "byText")
_IEFormElementSetValue($sub, GUICtrlRead($InputID + 4))
_IEFormElementSetValue($mes, GUICtrlRead($InputID + 5))
_IEFormElementSetValue($tele, GUICtrlRead($InputID + 6))
_IEFormSubmit($oForm)

EndFunc   ;==>Submit

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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