* @author Sebastian Mordziol * @license LGPL, see license.txt for details * @link http://www.php-tools.net */ /** * Main examples prepend file, needed *only* for the examples framework! */ include_once 'patExampleGen/prepend.php'; $exampleGen->displayHead( 'Example' ); // EXAMPLE START ------------------------------------------------------ /** * main patForms class */ require_once $neededFiles['patForms']; /** * patForms parser class */ require_once $neededFiles['patForms_Parser']; /** * patErrorManager class */ require_once $neededFiles['patErrorManager']; /** * localisation stuff */ require_once $neededFiles['patI18n_configure']; // create the parser object $parser =& patForms_Parser::createParser( "SimpleRenderer" ); // set the namespace $parser->setNamespace( "patForms" ); // create the hero handler object that will be used to handle the // hero: namespace we will add next. $heroHandler = new heroHandler; // now bind our namespace handler to the namespace we want to use. $parser->addNamespace( "hero", $heroHandler ); // parse the form template $parser->parseFile( "templates/example_parser_ns_handler.fhtml" ); // retrieve the form object $form =& $parser->getForm(); // set the parser as renderer $form->setRenderer( $parser ); // use auto-validation $form->setAutoValidate( 'save' ); // render the content $content = $form->renderForm(); // check the form and display error messages if any if( $form->isSubmitted() ) { displayErrors( $form ); // see the patExampleGen/customFunctions.php file } // now display the form echo $content; /** * Hero Handler class * * This simple callback handler is bound to the hero: * namespace in the form template, and will be used to * access the needed data. * * @access public * @package patForms * @subpackage Examples * @author Stephan Schmidt */ class heroHandler { /** * get a datasource * * This method will be called when a tag * is encountered. The class name will be built from the id attribute. * * @access public * @param array attributes of the tag * @param mixed content of the tag * @return object */ function &getDatasource( $attributes, $content ) { $dsName = "Datasource_".$attributes['id']; $ds = &new $dsName; return $ds; } /** * get the name of the page * * This method will be called when a tag * is encountered. * * This is just a dummy method, in real life you would build the page * name based on parameters. * * @access public * @param array attributes of the tag * @param mixed content of the tag * @return string */ function getPageName( $attributes, $content ) { return 'Pat\'s sensational Superhero competition'; } } /** * Example Marvel heroes datasource * * will be instantiated by heroHandler::getDatasource() * * @access public * @package patForms * @subpackage Examples * @author Stephan Schmidt */ class Datasource_Marvel { /** * get the values fo the datasource * * This is only a dummy, in real-life you would query a database * or do anything you like. * * @access public * @return array */ function getValues() { return array( array( "value" => 1, "label" => "Spider-Man" ), array( "value" => 2, "label" => "Invisible Woman" ), array( "value" => 3, "label" => "The Thing" ) ); } } /** * Example DC heroes datasource * * will be instantiated by heroHandler::getDatasource() * * @access public * @package patForms * @subpackage Examples * @author Stephan Schmidt */ class Datasource_DC { /** * get the values fo the datasource * * This is only a dummy, in real-life you would query a database * or do anything you like. * * @access public * @return array */ function getValues() { return array( array( "value" => 1, "label" => "Superman" ), array( "value" => 2, "label" => "Green Arrow" ), array( "value" => 3, "label" => "Wonder Woman" ), array( "value" => 4, "label" => "Aquaman" ), ); } } // EXAMPLE END ------------------------------------------------------ $exampleGen->displayFooter(); ?>