clonefish class overview
introduction
Clonefish itself is a class hierarchy. We'll mostly work with the main class, which is theclonefish 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 configuration array is described under "Input types" and "Validation types" in the menu).
- if values are received from a submitted form, we use the
validate()method - display the output using the
gethtml()method
<?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:
- template engine support (getVars() method)
- invalidation ( invalidate() method, addMessage() method )
- accessing element objects ( getElementByName() method, getValue() method )
