user-defined custom validation php javascript js

user-defined (custom) validation

Though the best way to define custom validation types is to simply extend Clonefish using your own validator class (feel free to explore the validators for examples!), a simple 'drop in' validator is also available in Clonefish. This one is used to get an element validated using JS or PHP expressions, which is a very quick and easy solution actually.

  • You can define a PHP and a JS expression or both, where can use placeholders like <FORM.fieldname> as shortcuts to elements.
  • In the PHP expression you can also access $this->form  which is the Clonefish object or $this->element which is the element holding the custom validator.
  • Please note that you can only use one error message for each validator (when you create an own validator class, you can return any error message depending on the type of problems encountered)

<?php 

$config 
= Array( 

  
'element' => Array( 

    
'type' => 'inputFile',      
    
// ...further element settings here...      

    
'validation' => Array(       

      Array(
       
'type' => 'custom',
       
'php'  => 'strlen( <FORM.fieldname> ) > 0'// php expression
       
'js'   => '<FORM.fieldname>.length > 0',    // javascript expression
       
'help=> 'Help message value for this validator only'
      
)
    )
  )
);

?>


Live examples:

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