Writing Form User Validation Functions

Form validation functions must accept one parameter, the pointer to the form currently being processed.

The call for a user validation function for a form is as follows:

int vfm_user(fmp)

DFORMPTR fmp;        /* Pointer to processed form         */

Your validation function should return a TRUE if the all the information on the form is valid. If the form is not valid (that is, at least one field on the form is invalid), your function should return FALSE and set the value of the global variable VAL_ERR to an appropriate value. If there is an invalid field, you may want to call sfm_nextitem() to specify which item or field to return to.

VAL_ERR is the global validation error variable. If VAL_ERR is set to a non-zero value, Vermont Views displays the error window and prints the appropriate error message. You can use one of the system error messages in your validation function, or you can create your own validation error message. You will find more information on using the validation error messages and creating your own messages later in this chapter.

Caution: Validation functions are intended only to check the data on the form. Do not exit or quit the form from your form validation functions.

You have complete access to the data entered on the form by the user. The functions fld_get() and srf_get() convert the data entered in the data field, memo field, or field in a scrollable region, respecting the data conversion field options set for the field (i.e., PICSKIP and TRAILBLANKS).

These functions are discussed in detail under "Getting the Converted Value of a Field" later in this chapter.

If one of the checks you perform in your form validation function fails, you should set the validation error code VAL_ERR and return FALSE.

More:

Moving Back to the Form in Case of an Invalid Form Entry


Home Contents Previous Next