Archive: Validation check


Validation check
  Hi all,

I have an installer that I am creating that asks the user to input two text fields using an installoptions custom page.

I am trying to get the installer to check if the fields are empty and then display an error message if either or both are empty. I have managed to get this to work using the following code for one of the text fields but how can i get it to check both of them?

;Page5
Page custom page5 ValidateCustom
Function page5
!insertmacro MUI_HEADER_TEXT "Folders" "Please share folders out and set share names here"
#Display the page
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "page5"
!insertmacro MUI_INSTALLOPTIONS_READ $1 "page5" "Field 2" "State"
!insertmacro MUI_INSTALLOPTIONS_READ $2 "page5" "Field 3" "State"
FunctionEnd

Function ValidateCustom
!insertmacro INSTALLOPTIONS_READ $1 "page5" "Field 2" "State"
!insertmacro INSTALLOPTIONS_READ $2 "page5" "Field 3" "State"
StrCmp $1 "" 0 +3
MessageBox MB_ICONEXCLAMATION|MB_OK "Please enter your name."
Abort
FunctionEnd

I highly recommend using LogicLib:
http://nsis.sourceforge.net/LogicLib


FunctionEnd 

>
I also recommend switching from InstallOptions to nsDialogs:
http://nsis.sourceforge.net/Docs/nsDialogs/Readme.html

but that's another thread %)

Thanks for that, having used your code thought it prompts me with the error message if there is anything in the boxes or not.

am I missing something?


If you didn't get any warnings.. not that I can think of;


OutFile "$%temp%\temp.exe"
Section
SectionEnd

!include "InstallOptions.nsh"

Function .onInit
!insertmacro INSTALLOPTIONS_EXTRACT "page5"
FunctionEnd

Page custom CustomPageFunction

Function CustomPageFunction
!insertmacro INSTALLOPTIONS_DISPLAY "page5"
Call ValidateCustom
FunctionEnd


Function ValidateCustom
!insertmacro INSTALLOPTIONS_READ $1 "page5" "Field 2" "State"
!insertmacro INSTALLOPTIONS_READ $2 "page5" "Field 3" "State"
MessageBox MB_OK "***91;$1***93;***91;$2***93;" /* to see what the values are */
${If} "$1" == ""
${OrIf} "$2" == ""
MessageBox MB_ICONEXCLAMATION|MB_OK "Please enter your name."
Abort
${EndIf}
FunctionEnd
>

I have finally managed to find some time to go back to this installer, I have this in place...


FunctionEnd 

>
Which works to a degree, problem is if I select 'Cancel' it brings the message 'Please ensure both fields are filled in. It does this regardless of wether the fields are filled in or not.

Anyone any ideas?

You must read the values from the INI file in the page leave function.

Stu


Hi,

I have taken the easy route out and used MinLen=1 in the .ini file. This way I don't get the message displaying but it should be pretty obvious to the end user what they have done wrong.

Now I just got to work out if I can use the same approach for radio buttons....


Doesn't seem to be as simple with radio buttons! I have three radio buttons on the one page.

I just want the page to not allow the user to go to the next one without selecting a button.


Like I said you need to check the contents of the INI file in the page LEAVE function. You are doing your checks in the page CREATE function. The INI file is not updated until the leave function is called. I recommend switching to nsDialogs. It makes stuff like this much easier.

Stu


Hi Stu,

After some extensive reading I have now realised also that using nsDialogs would have been a better route to take! Seen as I only have to resolve this last issue with the installer I am going to try and stick with InstallOptions for this project......

I am struggling to find some examples or an explanation of a LEAVE function.

Can you point me in the right direction of some reading material or explain it for me?


Check the testnotify script in the InstallOptions examples


Ok, using the example in http://nsis.sourceforge.net/Examples...testnotify.nsi I have come up with this, only problem is it displays the Error message if anything is selected or not......


Page6

Page custom page6 page6leave
>Function page6
>!insertmacro MUI_HEADER_TEXT "Checkboxes" "Please select a checkbox"
>#Display the page
>!insertmacro MUI_INSTALLOPTIONS_DISPLAY "page6"
>!insertmacro MUI_INSTALLOPTIONS_READ $R1 "page6" "Field 1" "State"
>!insertmacro MUI_INSTALLOPTIONS_READ $R2 "page6" "Field 2" "State"
>!insertmacro MUI_INSTALLOPTIONS_READ $R3 "page6" "Field 3" "State"
>FunctionEnd

>Function page6leave
ReadINIStr$0 "page6.ini" "Field 1" "State"
StrCmp $0 1 done
ReadINIStr$0 "page6.ini" "Field 2" "State"
StrCmp $0 1 done
ReadINIStr$0 "page6.ini" "Field 3" "State"
StrCmp $0 1 done
MessageBox MB_ICONEXCLAMATION
|MB_OK "You must select at least one install option!"
Abort
done:

>FunctionEnd
>

Use the MUI_INSTALLOPTIONS_READ macro (like you did in function "page5") instead of the ReadINIStr function.
And you better use the LogicLib library, as said before.