displayHead( 'Example' ); require_once 'patForms.php'; require_once 'patErrorManager.php'; /** * Attribute notes: * * - each token in the date format is automatically replaced * by a corresponding form element. Unknown tokens are * regarded as CDATA by the internal parser. For a list of * supported date tokens, see the $tokensIndex property of * the date element. * * - WARNING: due to a bug in PHP5 with the strtotime function * (see http://bugs.php.net/bug.php?id=28209), the [now] * directive will not include the current time, e.g. now will * return a date like 12.05.2004 00:00:00. I recommend using * timestamps directly when possible. * * - the returnformat attribute can be used to select the kind * of value the date element will return. Possible values are * [isodate], [timestamp]. Default: [isodate] */ $elementsDefinition = array( 'xmess' => array( 'type' => 'Date', 'attributes' => array( //'required' => 'yes', 'display' => 'yes', 'edit' => 'yes', 'label' => 'X-Mess eve', 'title' => 'X-Mess', 'description' => 'Tell me when you celebrate x-mess.', 'dateformat' => 'd.m.Y H:i:s', 'presets' => 'yes', // use select boxes? yes|no 'default' => time(), // timestamp, ISO 8601 date or strtotime-compatible string 'min' => '-1 year', // timestamp, ISO 8601 date or strtotime-compatible string 'max' => '+10 years', // timestamp, ISO 8601 date or strtotime-compatible string //'returnformat' => 'timestamp' // 'timestamp' or 'isodate' default: 'isodate' => ISO 8601 date ), ), ); // create the form $form =& patForms::createForm( $elementsDefinition, array( 'name' => 'myForm' ) ); $form->setNamespace('mynamespace'); // get the element to have some additonal fun with it $el =& $form->getElementByName( 'xmess' ); // If you want to retrieve the date in the date format you specified, // you can use the following method: //echo 'Formatted date: '.$el->getFormattedDate().'

'; // When using the set methods for the default, max and min dates, // you can also use a PEAR::Date object as parameter. //$el->setMax( new Date( strtotime( '+10 years' ) ) ); // If you can't remember what the ISO date format is, simply use the // provided method, getISOFormat() to get a format string for use with // PHP's date() function. //echo 'ISO date: '.date( $el->getISOFormat(), time() ); // create the needed renderer $renderer =& patForms::createRenderer( "Array" ); // set the renderer $form->setRenderer( $renderer ); // use auto-validation $form->setAutoValidate( 'save' ); // serialize the elements $elements = $form->renderForm(); // ERROR DISPLAY ------------------------------------------------------ // ask the form if it has been submitted and display errors. For // convenience and also to keep the examples easy to understand, all // the following examples will use teh helper methods of the examples // framework to display the errors and the form. if( $form->isSubmitted() ) { displayErrors( $form ); // see patExampleGen/customFunctions.php } // DISPLAY FORM ------------------------------------------------------ displayForm( $form, $elements ); // see patExampleGen/customFunctions.php // EXAMPLE END ------------------------------------------------------ $exampleGen->displayFooter(); echo '

' . wordwrap(htmlentities(print_r($form->getElement('xmess')->serialize(), true)), 200);
?>