root/trunk/examples/example_api_locale.php

Revision 117, 1.9 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  * Example that shows how to set a locale or error messages
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     // element definitions for this example
36     $elementsDefinition = array(
37         'username' => array(
38             'type' => 'String',
39             'attributes' => array(
40                 'required'        =>    'yes',
41                 'display'        =>    'yes',
42                 'edit'            =>    'yes',
43                 'label'            =>    'Nickname',
44                 'description'    =>    'Enter your nickname here.',
45                 'maxlength'        =>    '5',
46                 'minlength'        =>    '4',
47                 'default'        =>    'The Argh',
48                 'title'            =>    'Username',
49             ),
50         ),
51     );
52     
53     echo 'Setting locale to french (fr)... validation errors ';
54     echo 'will be displayed in french.<br/><br/>';
55     
56     // Set the locale to french. By doing this via a static method call,
57     // you can set it globally for all forms. Otherwise you can use this
58     // method to set it per each form object.
59     patForms::setLocale( 'fr' );
60
61     // create our form
62     $form =& patForms::createForm( $elementsDefinition );
63     
64     // tell the form it has been submitted
65     $form->setSubmitted( true );
66
67     // validate the element - this will always fail here on purpose to show
68     // the error message
69     $form->validateForm();
70     
71     // display the errors
72     displayErrors( $form ); // see patExampleGen/customFunctions.php
73
74
75     
76     
77     // EXAMPLE END ------------------------------------------------------
78     $exampleGen->displayFooter();
79 ?>
80
Note: See TracBrowser for help on using the browser.