root/tags/RELEASE_0_9_0B1/examples/example_creator_autosave.php

Revision 117, 2.1 kB (checked in by argh, 4 years ago)

Massive update of the examples collection; added the patExampleGen examples framework; commented all examples; reworked all the templates...

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 <?php
2 /**
3  * patForms_Creator_DB examples
4  *
5  * patForms_Creator is a subpackage of patForms that provides
6  * several formbuilder classes that create a form from
7  * a datasource.
8  *
9  * WARNING:
10  * The Creator subpackage is still in devel state!
11  *
12  * @access        public
13  * @package        patForms
14  * @subpackage    Examples
15  * @author        Stephan Schmidt <schst@php-tools.net
16  * @author        Sebastian Mordziol <argh@php-tools.net>
17  * @license        LGPL, see license.txt for details
18  * @link        http://www.php-tools.net
19  */
20
21     /**
22      * Main examples prepend file, needed *only* for the examples framework!
23      */
24     include_once 'patExampleGen/prepend.php';
25     $exampleGen->displayHead( 'Example' );
26
27     
28     // EXAMPLE START ------------------------------------------------------
29
30     /**
31      * main patForms class
32      */
33     require_once $neededFiles['patForms'];
34     
35     /**
36      * patErrorManager class
37      */
38     require_once $neededFiles['patErrorManager'];
39
40     // the DSN to your database
41     $dsn = 'mysql://root:@localhost/pat';
42     
43     // the table name
44     $dbt = 'patForms_Storage';
45
46     // create the creator :)
47     $creator = &patForms::createCreator( 'DB_Mysql' );
48     
49     // create the form object from the given database
50     $form =& $creator->create( $dsn, $dbt );
51     
52     // create the needed renderer
53     $renderer    =&    patForms::createRenderer( "Array" );
54     
55     // set the renderer
56     $form->setRenderer( $renderer );
57     
58     // use auto-validation
59     $form->setAutoValidate( 'save' );
60
61     // want to create and store in one go? Then combine the creator with
62     // a storage object :)
63     $storage =& patForms::createStorage( 'DB' );
64     
65     // and set up... done!
66     $storage->setStorageLocation( $dsn, $dbt );
67     $storage->setPrimaryField( 'user' );
68     
69     $form->setStorage( $storage );
70
71     // serialize the elements
72     $elements = $form->renderForm();
73     
74     
75     // ERROR DISPLAY ------------------------------------------------------
76     if( $form->isSubmitted() )
77     {
78         displayErrors( $form );    // see patExampleGen/customFunctions.php
79     }
80
81     // DISPLAY FORM ------------------------------------------------------
82     displayForm( $form, $elements ); // see patExampleGen/customFunctions.php
83
84
85     
86     
87     // EXAMPLE END ------------------------------------------------------
88     $exampleGen->displayFooter();
89 ?>
Note: See TracBrowser for help on using the browser.