clonefish class overview
The class
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:
- create an instance of this class, and
- define the form fields using the configuration array (the format of this array is described under "Input types" and "Validation types" in the menu).
- if values are received from a submitted form, we use the
$form->validate()
method - display the output using the
$form->getHTML()
method
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:
- template engine support:
$clonefish->getVars()
- invalidation:
$clonefish->invalidate()
,$clonefish->addMessage()
- accessing element objects:
$clonefish->getElementByName()
,$clonefish->getValue()
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 );
if ( isset( $_POST['login'] ) && $clonefish->validate() ) {
// do some action here
}
else
echo
"<html><body>" .
$clonefish->getHTML() .
"</body></html>";
?>
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 formslearn more