|
WikiSh /
Forms-RequiredFieldsThis form simply provides for entering a name in a field and then validates that the field had something in it. It provides an error message if the field is not filled in and a congratulatory message if the field was filled in. See HERE for a working version of this simple form. Note that this page gives a description of the entire form. Other pages in this section of WikiSh documentation will focus in on only "the interesting stuff" which varies from form to form.
{(wikish_form QUICKFORM PROCESS)}
{(wikish source {$FullName}#validate)}
Please enter your name: (:input text name:)
(:input submit save Save:)
(:input end:)
(:if false:)
[[#validate]]
if test -z ${save} # the user didn't press the "save" button
then
exit
fi
#
# After this comes "the interesting stuff"
#
if test -z ${name} # if name is blank
then
echo "%red% Name is a required field! Please try again.%%"
else
echo "%green% Well done, ${name}! You entered your name!%%"
fi
#
# Here ends "the interesting stuff"
#
[[#validateEnd]]
(:ifend:)
(:messages:)
The first line (below) is just a quick way to get your form set up to validate to the current page: {(wikish_form QUICKFORM PROCESS)}
The second line (below) tells wikish that you want to run the validation script contained in the #validate section on this page: {(wikish source {$FullName}#validate)}
Lines 3-5 (below) use vanilla pmwiki forms to set up your form: Please enter your name: (:input text name:) (:input submit save Save:) (:input end:) The lines between We start with a check to see if the submit button was actually pressed. If the user didn't hit the submit button then we don't want do any validation (validation occurs after the user has entered something, not when the form is loaded in its blank form!):
if test -z ${save} # the user didn't press the "save" button
then
exit
fi
The next 5 lines are the key - we check if the field is blank and generate a message based on the results of that check.
if test -z ${name} # if name is blank
then
echo "%red% Name is a required field! Please try again.%%"
else
echo "%green% Well done, ${name}! You entered your name!%%"
fi
The final line, |