Validation types

Clonefish has strong validation features to support building secure forms. Elements are validated two times: once in the browser using JavaScript, and once again on the server using PHP.

To use validation you only need to add a few lines to the element configuration, for example: 

<?php

$config = Array(
  'name' => Array(
    'type'       => 'inputText',
    'validation' => Array(
      Array( 'type' => 'required' )
    )
  )
);

?>

Well, that's the simplest validation. But there's much more! 

  • As you may have noticed, the validation setting is an array of arrays: this approach allows adding multiple validation rules to a single element.
  • Depending on the validation type you can specify further settings when defining a validation: for example a string validation can have minimum and maximum string length, or regular expressions to match.
  • The validation types all have some kind of built-in help messages, when the validation fails - however, they're kind of generic, so you may need to override them. Help messages can be set on element level or validation level using the 'help' setting.
  • A very powerful validation feature is the dependency handling: you can tie a validation to the value of an expression. Imagine you have a drop-down select with some options an "other" option. When the user chooses the "other" option, you want the user to fill a text field. To make it work you simple set the validation of the text field to depend on the value of the current selection.


 

form validation for developers!

clonefish is a proven, mature form generator class that helps PHP developers to create, validate and process secure, flexible and easy-to-maintain forms
learn more
Bookmark and Share