root/branches/gettext/examples/example_creator_autosave.php

Revision 394, 2.2 kB (checked in by gerd, 1 year ago)

Switched to patI18n

  • removed all setLocale / getLocale functions from patForms, elements etc.
  • use patI18n::dgettext with textdomain "patForms"
  • added patI18n example
  • added helper script to setup patI18n
  • mended examples accordingly
  • 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     /**
41      * localisation stuff
42      */
43     require_once $neededFiles['patI18n_configure'];
44
45
46     // the DSN to your database
47     $dsn = 'mysql://root:@localhost/pat';
48     
49     // the table name
50     $dbt = 'patForms_Storage';
51
52     // create the creator :)
53     $creator = &patForms::createCreator( 'DB_Mysql' );
54     
55     // create the form object from the given database
56     $form =& $creator->create( $dsn, $dbt );
57     
58     // create the needed renderer
59     $renderer    =&    patForms::createRenderer( "Array" );
60     
61     // set the renderer
62     $form->setRenderer( $renderer );
63     
64     // use auto-validation
65     $form->setAutoValidate( 'save' );
66
67     // want to create and store in one go? Then combine the creator with
68     // a storage object :)
69     $storage =& patForms::createStorage( 'DB' );
70     
71     // and set up... done!
72     $storage->setStorageLocation( $dsn, $dbt );
73     $storage->setPrimaryField( 'user' );
74     
75     $form->setStorage( $storage );
76
77     // serialize the elements
78     $elements = $form->renderForm();
79     
80     
81     // ERROR DISPLAY ------------------------------------------------------
82     if( $form->isSubmitted() )
83     {
84         displayErrors( $form );    // see patExampleGen/customFunctions.php
85     }
86
87     // DISPLAY FORM ------------------------------------------------------
88     displayForm( $form, $elements ); // see patExampleGen/customFunctions.php
89
90
91     
92     
93     // EXAMPLE END ------------------------------------------------------
94     $exampleGen->displayFooter();
95 ?>
Note: See TracBrowser for help on using the browser.