root/branches/gettext/examples/example_api_autovalidate.php

Revision 394, 2.4 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  * Example showing the autovalidation feature.
4  *
5  * $Id$
6  *
7  * @access        public
8  * @package        patForms
9  * @subpackage    Examples
10  * @author        Sebastian Mordziol <argh@php-tools.net>
11  * @license        LGPL, see license.txt for details
12  * @link        http://www.php-tools.net
13  */
14
15     /**
16      * Main examples prepend file, needed *only* for the examples framework!
17      */
18     include_once 'patExampleGen/prepend.php';
19     $exampleGen->displayHead( 'Example' );
20
21     
22     // EXAMPLE START ------------------------------------------------------
23
24     /**
25      * main patForms class
26      */
27     require_once $neededFiles['patForms'];
28     
29     /**
30      * patErrorManager class
31      */
32     require_once $neededFiles['patErrorManager'];
33     
34     /**
35      * localisation stuff
36      */
37     require_once $neededFiles['patI18n_configure'];
38
39     
40     // element definitions for this example
41     $elementsDefinition = array(
42         'username' => array(
43             'type' => 'String',
44             'attributes' => array(
45                 'required'        =>    'yes',
46                 'label'            =>    'Username',
47                 'description'    =>    'Enter your username here. Maximum length: [ELEMENT_MAXLENGTH]',
48                 'maxlength'        =>    '15',
49                 'minlength'        =>    '4',
50                 'title'            =>    'Username',
51             ),
52         ),
53     );
54     
55     // create the form
56     $form    =&    patForms::createForm( $elementsDefinition, array( 'name' => 'myForm' ) );
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 - in this case, the form is validated
65     // automatically when renderForm() is called, and you can
66     // check whether the form is valid by checking for validation
67     // errors via the getValidationErrors() method.
68     $form->setAutoValidate( 'save' );
69
70     // serialize the elements
71     $elements = $form->renderForm();
72     
73     
74     // ERROR DISPLAY ------------------------------------------------------
75     // ask the form if it has been submitted. Note that you
76     // do not need the setSubmitted() and validateForm() function
77     // calls with the autovalidation feature. You just need to
78     // make sure you call this after the renderForm() call, at which
79     // point the form is automatically validated.
80     if( $form->isSubmitted() )
81     {
82         displayErrors( $form ); // see patExampleGen/customFunctions.php
83     }
84
85     // DISPLAY FORM ------------------------------------------------------
86     displayForm( $form, $elements ); // see patExampleGen/customFunctions.php
87
88
89     
90     
91     // EXAMPLE END ------------------------------------------------------
92     $exampleGen->displayFooter();
93 ?>
94
Note: See TracBrowser for help on using the browser.