]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/framework/Web/UI/TForm.php
baculum: New Baculum API and Baculum Web
[bacula/bacula] / gui / baculum / framework / Web / UI / TForm.php
1 <?php
2 /**
3  * TForm class file
4  *
5  * @author Qiang Xue <qiang.xue@gmail.com>
6  * @link https://github.com/pradosoft/prado
7  * @copyright Copyright &copy; 2005-2016 The PRADO Group
8  * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT
9  * @package System.Web.UI
10  */
11
12 /**
13  * TForm class
14  *
15  * TForm displays an HTML form. Besides regular body content,
16  * it displays hidden fields, javascript blocks and files that are registered
17  * through {@link TClientScriptManager}.
18  *
19  * A TForm is required for a page that needs postback.
20  * Each page can contain at most one TForm. If multiple HTML forms are needed,
21  * please use regular HTML form tags for those forms that post to different
22  * URLs.
23  *
24  * @author Qiang Xue <qiang.xue@gmail.com>
25  * @package System.Web.UI
26  * @since 3.0
27  */
28 class TForm extends TControl
29 {
30         /**
31          * Registers the form with the page.
32          * @param mixed event parameter
33          */
34         public function onInit($param)
35         {
36                 parent::onInit($param);
37                 $this->getPage()->setForm($this);
38         }
39
40         /**
41          * Adds form specific attributes to renderer.
42          * @param THtmlWriter writer
43          */
44         protected function addAttributesToRender($writer)
45         {
46                 $writer->addAttribute('id',$this->getClientID());
47                 $writer->addAttribute('method',$this->getMethod());
48                 $uri=$this->getRequest()->getRequestURI();
49                 $writer->addAttribute('action',str_replace('&','&amp;',str_replace('&amp;','&',$uri)));
50                 if(($enctype=$this->getEnctype())!=='')
51                         $writer->addAttribute('enctype',$enctype);
52
53                 $attributes=$this->getAttributes();
54                 $attributes->remove('action');
55                 $writer->addAttributes($attributes);
56
57                 if(($butt=$this->getDefaultButton())!=='')
58                 {
59                         if(($button=$this->findControl($butt))!==null)
60                                 $this->getPage()->getClientScript()->registerDefaultButton($this, $button);
61                         else
62                                 throw new TInvalidDataValueException('form_defaultbutton_invalid',$butt);
63                 }
64         }
65
66         /**
67          * Renders the form.
68          * @param THtmlWriter writer
69          */
70         public function render($writer)
71         {
72                 $page=$this->getPage();
73
74                 $this->addAttributesToRender($writer);
75                 $writer->renderBeginTag('form');
76
77                 $cs=$page->getClientScript();
78                 if($page->getClientSupportsJavaScript())
79                 {
80                         $cs->renderHiddenFieldsBegin($writer);
81                         $cs->renderScriptFilesBegin($writer);
82                         $cs->renderBeginScripts($writer);
83
84                         $page->beginFormRender($writer);
85                         $this->renderChildren($writer);
86                         $cs->renderHiddenFieldsEnd($writer);
87                         $page->endFormRender($writer);
88
89                         $cs->renderScriptFilesEnd($writer);
90                         $cs->renderEndScripts($writer);
91                 }
92                 else
93                 {
94                         $cs->renderHiddenFieldsBegin($writer);
95
96                         $page->beginFormRender($writer);
97                         $this->renderChildren($writer);
98                         $page->endFormRender($writer);
99
100                         $cs->renderHiddenFieldsEnd($writer);
101                 }
102
103                 $writer->renderEndTag();
104         }
105
106         /**
107          * @return string id path to the default button control.
108          */
109         public function getDefaultButton()
110         {
111                 return $this->getViewState('DefaultButton','');
112         }
113
114         /**
115          * Sets a button to be default one in a form.
116          * A default button will be clicked if a user presses 'Enter' key within
117          * the form.
118          * @param string id path to the default button control.
119          */
120         public function setDefaultButton($value)
121         {
122                 $this->setViewState('DefaultButton',$value,'');
123         }
124
125         /**
126          * @return string form submission method. Defaults to 'post'.
127          */
128         public function getMethod()
129         {
130                 return $this->getViewState('Method','post');
131         }
132
133         /**
134          * @param string form submission method. Valid values include 'post' and 'get'.
135          */
136         public function setMethod($value)
137         {
138                 $this->setViewState('Method',TPropertyValue::ensureEnum($value,'post','get'),'post');
139         }
140
141         /**
142          * @return string the encoding type a browser uses to post data back to the server
143          */
144         public function getEnctype()
145         {
146                 return $this->getViewState('Enctype','');
147         }
148
149         /**
150          * @param string the encoding type a browser uses to post data back to the server.
151          * Commonly used types include
152          * - application/x-www-form-urlencoded : Form data is encoded as name/value pairs. This is the standard encoding format.
153          * - multipart/form-data : Form data is encoded as a message with a separate part for each control on the page.
154          * - text/plain : Form data is encoded in plain text, without any control or formatting characters.
155          */
156         public function setEnctype($value)
157         {
158                 $this->setViewState('Enctype',$value,'');
159         }
160
161         /**
162          * @return string form name, which is equal to {@link getUniqueID UniqueID}.
163          */
164         public function getName()
165         {
166                 return $this->getUniqueID();
167         }
168 }
169