Forms-RangeValues

This form simply provides for entering a number in a field and then validates that the value entered was between 1 and 10. It provides an error message if the field is out of range and a congratulatory message if the value was valid. See HERE for a working version of this simple form.

{(wikish_form QUICKFORM PROCESS)}
{(wikish source {$FullName}#validate)}
Please enter your a number between 1 and 10: (:input text num:)
(:input submit save Save:)
(:input end:)

(:if false:)
[[#validate]]
if test -z ${save} # the user didn't press the "save" button
then
   exit
fi
#
# HERE IS THE INTERESTING PART
#
if test ${num} -lt 1 || test ${num} -gt 10 # if name is blank
then
   echo "%red% Your number is out of range.  Please try again.%%"
else
   echo "%green% Well done! ${num} is a valid number!%%"
fi
#
# HERE ENDS THE INTERESTING PART
#
[[#validateEnd]]
(:ifend:)

(:messages:)

If you have any questions about the part of the form that comes before "HERE IS THE INTERESTING PART" or after "HERE ENDS THE INTERESTING PART" then please refer to this page for an explanation.

The interesting part simply checks to see if the number is less than (you express numeric "less than" with the "-lt" option) 1 or (the "or" operator is "||") the number is greater than ("-gt") 10. If it is then it generates an error message. If it isn't then it generates a feel-good message.

Note that we haven't yet checked if the user entered a NUMERIC value. If they entered "Sam" when we asked for a number then we would get an unsightly error message from wikish when it tried to compare "Sam" with the numeric operator "test -lt" or "test -gt". There are several ways around that, but we'll get to that later.