Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

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