Developer's Guide :: Using FormValidator

From Delphi for PHP Documentation Wiki

Jump to: navigation, search

FormValidator is a component that makes easy for you to test form values against an specific set of rules. Rules can be designed using the property editor for the Rules property, using the Object Inspector.

If none of the properties and types of built-in validations are suited for your needs, you can write your custom code using the OnValidate event for the rule. On that event, using javascript code, you can check if the value on a field meet your needs, and return true in that case, if not, return false, so the validator will show the error message to the user and will prevent the form from being submitted.

This is an example of the code you need to write on the OnValidate event for a rule:

 
       function Rule1Validate($sender, $params)
       {
       ?>
            edit1=findObj('Edit1');
            if (edit1.value!='') return(true);
            else return(false);
       <?php
 
       }
 

In this case, we get a reference to the Edit1 input box, and check its value against an empty string, and if empty, return false.

Personal tools