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(

  
'selectdate1' => Array(
    
'type'           => 'selectdate',
    
'displayname'    => 'The default selectdate',
    
'value'          => date("Y-m-d"),
    
'postfix'        => '<br />no null values, defaults to today',
    
'null'           => false,
  ),

  
'selectdate2' => Array(
    
'type'           => 'selectdate',
    
'displayname'    => 'A different layout',
    
'postfix'        => '<br />default null values',
    
'layout'         => '<nobr>%M %D %Y</nobr>',
  ),

  
'selectdate3' => Array(
    
'type'           => 'selectdate',
    
'displayname'    => 'Year trick 1 (incrementing)',
    
'layout'         => '<nobr>%M %D %Y</nobr>',
    
'yearfrom'       => '1990',
    
'yearuntil'      => '2000',
    
'postfix'        => '<br />...and redefined null values',
    
'null'           => Array( '' => '-- choose! --' ),
  ),

  
'selectdate4' => Array(
    
'type'           => 'selectdate',
    
'displayname'    => 'Year trick 2 (decrementing)',
    
'postfix'        => '<br />...and the months are abbreviated.',
    
'layout'         => '<nobr>%M %D %Y</nobr>',
    
'yearfrom'       => '2000',
    
'yearuntil'      => '1990',
    
'months'         => Array(
      
=> 'Jan',
      
=> 'Feb',
      
=> 'Mar',
      
=> 'Apr',
      
=> 'May',
      
=> 'Jun',
      
=> 'Jul',
      
=> 'Aug',
      
=> 'Sep',
     
10 => 'Oct',
     
11 => 'Nov',
     
12 => 'Dec',
    ),
  ),

  
'selectdate5' => Array(
    
'type'           => 'selectdate',
    
'displayname'    => 'Format change',
    
'postfix'        => '
       <br />Find the "data" section below to check that
       the returned format is different: changes to D-M-Y!
      '
,
    
'format'         => '%D-%M-%Y',
  ),

  
'selectdate6' => Array(
    
'type'           => 'selectdate',
    
'displayname'    => 'Time',
    
'postfix'        => '
      <br />Handles hours, minutes and seconds too!
      '
,
    
'layout'         => '%Y-%M-%D, %h : %m : %s',
    
'format'         => '%Y-%M-%D %h:%m:%s',
  ),

);

?>

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!