source

This is the config array for clonefish which generates the form you've just seen. How can you use such an array?

<?php

$config 
= Array(
  
'login' => Array(
    
'type'           => 'inputText',
    
'displayname'    => 'Login name, min. 5, max. 15 chars',
    
'help'           => 'The login name has to be at least 5 characters long, and must not be longer than 15 characters',
    
'validation'     => Array(
      Array( 
        
'type'    => 'string',
        
'minimum' => 5,
        
'maximum' => 15,
      ),
    ),
  ),

  
'password' => Array(
    
'type'           => 'inputPassword',
    
'displayname'    => 'Password, min. 5, max. 15 chars',
    
'help'           => 'The password has to be at least 5 characters long, and must not be longer than 15 characters',
    
'validation'     => Array(
      Array( 
        
'type'    => 'string',
        
'minimum' => 5,
        
'maximum' => 15,
      ),
    ),
  ),

  
'passwordverify' => Array(
    
'type'           => 'inputPassword',
    
'displayname'    => 'Password again',
    
'help'           => 'The two password has to be the same',
    
'validation'     => Array(
      Array( 
        
'type'    => 'string',
        
'equals'  => 'password',
      ),
    ),
  ),
  
  
'email' => Array(
    
'type'           => 'inputText',
    
'displayname'    => 'Your e-mail address',
    
'help'           => 'A valid e-mail address is required',
    
'validation'     => Array(
      Array(
        
'type'    => 'string',
        
// an e-mail address format verification 
        // regular expression
        
'regexp' => '/^[\._0-9a-z-]+@[0-9a-z][-0-9a-z\.]*\.[a-z]{2,4}$/' 
      
),
    ),
  ),
);


?>

usage example

To create a form using this array you'll only need a few lines of code:

<?php

// create the form object
$clonefish = new clonefish'loginform''test.php''POST' );

// setup codepage so your data will be handled
// perfectly by the appropriate string functions
$clonefish->codepage         'utf-8';
$clonefish->multibytesupport 'multibyteutf8';

// add the form elements (fields) pre-filled with
// values from $_POST
$clonefish->addElements$config$_POSTget_magic_quotes_gpc() );

// validate the form if the form has been submitted
if ( count$_POST ) && $clonefish->validate() ) {
  
// form is valid, go and store values in database, etc.
  // $clonefish->getElementValues() provides a 
  // normalized value array.
}
else
  
// if the form wasn't submitted yet or the validation
  // had failed, show the form (automatically
  // including error messages)
  
echo 
    
"<html><body>" 
    
$clonefish->getHTML() .
    
"</body></html>";

?>

But there's so much more than just displaying the form - be sure to read the
reference pages and the introduction!