Printable Version
 Updates

 Documentation

 Support & Training

 Community
  Online Forum
  Newsgroups
Setting Error Messages in the OnValidate event

Products:   
Areas: ASP, ColdFusion, Perl 

The Onvalidate event is provided in record forms to enable you to validate the fields submitted in the record form. During the process of validation, you can prevent the form from being processed further by setting an error message. By default, the CodeCharge code does a mandatory check on all fields to make sure that the submitted values are of the correct data type. Also, if the Required and Unique properties of any fields have been set, the code also validates these fields accordingly. Whenever a problem is encountered with a submitted value, the code adds an error message to the Errors collection. What this means is that if the Errors collection is not empty, the form will not be processed to completion. Rather, the user will be redirected to the submitting page which will now contain the error messages registered in the Errors collection.

In addition to the default validation checks, you can also check for and register your own errors. This capability comes in handy where you want to check for conditions beyond those provided by CodeCharge Studio.

Basically, you register an error message by using the addErrors method. For instance in ASP, the code would be of the form:

FormName.Errors.addError "This is a custom error message"

and in PHP, the code would be:

global $FormName;
$FormName->Errors->addError(""This is a custom error message");

and in Cold Fusion, the code would be:

<CFSET strErrFormName= strErrFormName & "This is a custom error message">

Ideally, the above code would be placed in the OnValidate event which occurs before the forms changes are executed against the database. However, you can also place the code in events such as Before Insert, Before Update, Before Delete i.e. events that occur before the form action is executed against the database.



Viewed 16848 times.   Last updated: 11/15/2002 1:09:25 AM