KoolForm KoolForm FullVersion released on 25/11/2016

Validation - First Look

Please enter information

Description & Sample code

There are 4 types of validators:

  • 1. KoolRequiredFieldValidator : Check if a field is not empty
  • 2. KoolRangeValidator : Check if value is within a defined range.
  • 3. KoolRegularExpressionValidator : Check if field value is conformed to regular expression
  • 4. KoolCustomValidator : Provide your own custom client-side validation.

To use KoolRequiredFieldValidator, you do as follow:

  • 1. Create object and add to form: $txtName_RequiredFieldValidator = $myform_manager->AddControl(new KoolRequiredFieldValidator("txtName_RequiredFieldValidator"));
  • 2. Set which field to validate: $txtName_RequiredFieldValidator->TargetId = "txtName";
  • 3. Set error message which will be show when validation is failed: $txtName_RequiredFieldValidator->ErrorMessage = "The textbox can not be empty!";
  • 4. Render the validator at your html place:
    <?php echo $txtName_RequiredFieldValidator->Render();?>

* In the step 4, if you define the form with $myform_manager->RenderWithExistingMarkup = true;, you do not above render. Instead, you create a span in your html like this:

<span id="txtName_RequiredFieldValidator"><span>

The way of iniitiating KoolRangeValidator, KoolRegularExpressionValidator is the same. However,

  • 1. In the KoolRangeValidator, you provide value for $MinValue and $MaxValue properties.
  • 2. In the KoolRegularExpressionValidator, you provide value for $Expression property.

if you are using KoolCustomValidator, you will provide the name of your custom client-side validator function for $ClientValidationFunction property. Your custome validation function is an javascript function which returns true if valid and returns false if not valid.