Input Validation

See also FoxValidationExamples

Fox has two levels for input checking, simple client-side javascript and server-side php. You can use both methods in the same form.
Simple client-side check using javascript :

(:fox formname ... formcheck=name1,name2..:)
a simple client-side (instant) java script check to alert if a named input field is left empty. This is only effective if user has a javascript enabled browser.

More reliable and detailed server side validation using php:

(:foxcheck name [match='STRING'] [regex='PATTERN'] [empty=1]
  [if='CONDITION'] [msg='ERROR MSG']:)
PHP input validation check on input from field name. You can also use a list of names; name1,name2,.. etc.

Parameters:

  • name is the first argument. Or name=name1,name2,.. - There needs to be input from named fields, if a named field is left empty the check fails, unless parameter empty=1 is set. If the field is named by name=$:Var, use as name ptv_Var.
  • match is the second argument. Or use match='STRING'. Input has to match STRING. Wiki wildcard characters are allowed.
  • regex='pattern' - Input has to match regex pattern. Use this to create more precise pattern masks than match.
  • empty=1 allows empty input to bypass the input check. If ptvclear=1 or ptvclear=name is set in the (:fox ...:) form's directive, an empty input field will clear a PTV associated with the name. Otherwise with the empty=1 parameter set an input of the $FoxClearPTVFmt string (NULL by default) will clear the PTV.
  • if='condition' - Input has to fulfill condition. Conditions for use are the same as with the (:if ...:) conditional markup.
  • msg='error message' - If the input check fails error message will be displayed using (:foxmessage ..:) markup. If msg is not set a default error message will be used instead.
(:foxmessage [formname] [name] [list=nocheck]:)
Markup to display Fox error and success messages. Output is inline text and can by styled with wiki markup, for instance like %red%'''(:foxmessage:)''' giving a red bold message.

Usage:

  • (:foxmessage:) will display all Fox messages.
  • (:foxmessage formname:) will display all Fox messages resulting from submission of form formname.
  • (:foxmessage formname list=nocheck:) will display Fox messages from form formname but exclude all messages resulting from input checks set with (:foxcheck name ..:).
  • (:foxmessage formname list=check:) will display messages resulting from input checks set with (:foxcheck name ..:), but exclude all other messages.
  • (:foxmessage formname name:) will display fox error message resulting from input check set with (:foxcheck name ..:). Use this markup for instance beside each input field, to give field specific error messages right next to the field causing the error.
  • If the field to be checked is named by name=$:Var (for PTVs when using (:input default source ....:)), use as name ptv_Var.
(:if foxerror <formname> <fieldname>:) conditional

The foxerror conditional is set true if an input validation error occurs as per setting of (:foxcheck ....:) markup. Either use conditional without <formname> and <fieldname> in a general way, or specify the fox form name and a specific input field name, to set a condition for trapping field specific input errors. In this way one could bypass the use of (:foxmessage ...:) and msg='...' within the (:foxcheck ... :) markup.


<< Input Form Controls | Index | Template Markup >>