clonefish logo

clonefish class overview

introduction

Clonefish itself is a class hierarchy. We'll mostly work with the main class, which is the clonefish class. To use clonefish, we have to:
  1. create an instance of this class, and
  2. define the form fields using the configuration array (the format of this configuration array is described under "Input types" and "Validation types" in the menu).
  3. if values are received from a submitted form, we use the validate() method
  4. display the output using the gethtml() method
A simple example:
<?php

include('clonefish/clonefish.php');
include('clonefish/messages_en.php');

$config = Array(
  'login' => Array(
    'type'        => 'inputText',  // type of field
    'displayname' => 'Your name:', // label
    'help'        => 'Please enter your name!', 
       // help message to display for invalid input values
    'validation'  => Array(
       Array( 'type' => 'required' )
       // don't accept empty inputs
    )
  ),
);

$clonefish = new clonefish( 'loginform', 'test.php', 'POST' );
$clonefish->addelements( $config, $_POST, get_magic_quotes_gpc() );

if ( isset( $_POST['login'] ) && $clonefish->validate() ) {
  // do some action here
}
else
  echo 
    "<html><body>" . 
    $clonefish->gethtml() .
    "</body></html>";

?>

That's all!

On the first glance, it might seem to be too much work for a simple form, but when you start using clonefish, you'll find it very handy and efficient for more complicated forms - and it's always the same few lines code as above, just with a different configuration array!

Beyond the basics there are additional features already proven in dozens of applications, like: