1: <?php
2:
3: namespace webfilesframework\io\form;
4:
5: use webfilesframework\MSite;
6: use webfilesframework\io\form\formItem\MAbstractFormItem;
7:
8: 9: 10: 11: 12: 13:
14: class MForm
15: {
16:
17: private $action;
18: private $method;
19:
20: private $formItems;
21:
22: private $useSubmitButton = true;
23: private $submitButtonText = "Submit";
24:
25: 26: 27: 28: 29: 30:
31: public function __construct($action, $method)
32: {
33: $this->action = $action;
34: $this->method = $method;
35:
36: $this->formItems = array();
37:
38: }
39:
40:
41: 42: 43:
44: function getCode()
45: {
46:
47: $out = $this->getHeaderCode();
48: $out .= $this->getFormItemsCode();
49: $out .= $this->getFooterCode();
50:
51: return $out;
52: }
53:
54: 55: 56: 57:
58: function getHeaderCode()
59: {
60: $out = "<form method=\"" . $this->method . "\" action=\"" . $this->action . "\" >";
61: return $out;
62: }
63:
64: 65: 66: 67:
68: function getFooterCode()
69: {
70: $out = "";
71: if ($this->useSubmitButton) {
72: $out = "<div>";
73: $out .= "<input type=\"submit\" value=\"absenden\" dojoType=\"dijit.form.Button\" id=\"submitButton\" label=\"" . $this->submitButtonText . "\">";
74: $out .= "</div>";
75:
76: }
77: $out .= "</form>";
78:
79: return $out;
80: }
81:
82: function getFormItemsCode()
83: {
84:
85: $out = "";
86:
87: foreach ($this->formItems as $value) {
88: $out .= $value->getCode();
89: }
90:
91: return $out;
92: }
93:
94: 95: 96: 97: 98:
99: function addFormItem(MAbstractFormItem $formItem, $precedingFormItemName = null)
100: {
101:
102: if ($precedingFormItemName == null) {
103: array_push($this->formItems, $formItem);
104: } else {
105:
106: $formItems = array();
107:
108: foreach ($this->formItems as $iteratingFormItem) {
109:
110: $formItems[] = $iteratingFormItem;
111: if ($iteratingFormItem->getName() == $precedingFormItemName) {
112: $formItems[] = $formItem;
113: }
114: }
115:
116: $this->formItems = $formItems;
117:
118: }
119:
120: }
121:
122: 123: 124: 125: 126:
127: function setAction($action)
128: {
129: $this->action = $action;
130: }
131:
132: 133: 134: 135: 136:
137: function setMethod($method)
138: {
139: $this->method = $method;
140: }
141:
142: public static function addFormHeadersToSite($site)
143: {
144:
145:
146: $site->addHeader("<link rel=\"stylesheet\" href=\"http://ajax.googleapis.com/ajax/libs/dojo/1.8.10/dijit/themes/claro/claro.css\">");
147: $site->addHeader("<script type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/dojo/1.8.10/dojo/dojo.js\" data-dojo-config=\"isDebug: true, parseOnLoad: true\"></script>");
148: $site->addHeader("<script type=\"text/javascript\">
149:
150:
151: dojo.require(\"dojo.on\");
152: dojo.require(\"dojox.validate\");
153: dojo.require(\"dojox.validate.us\");
154: dojo.require(\"dojox.validate.web\");
155:
156:
157: /* basic dijit classes */
158: dojo.require(\"dijit.dijit\");
159: dojo.require(\"dijit.form.Form\");
160: dojo.require(\"dijit.form.Button\");
161: dojo.require(\"dijit.form.Select\");
162: dojo.require(\"dijit.form.FilteringSelect\");
163: dojo.require(\"dijit.form.TextBox\");
164: dojo.require(\"dijit.form.ValidationTextBox\");
165: dojo.require(\"dijit.form.DateTextBox\");
166: dojo.require(\"dijit.form.TimeTextBox\");
167: dojo.require(\"dijit.form.Textarea\");
168: dojo.require(\"dijit.form.CheckBox\");
169:
170: dojo.require(\"dijit.Dialog\");
171: dojo.require(\"dijit.Editor\");
172:
173:
174: dojo.require(\"dojo.dom\");
175: dojo.require(\"dojo.parser\");
176: dojo.require(\"dojox.validate\");
177: </script>
178: ");
179:
180: MSite::getInstance()->addBodyAttribute('id', 'ff-meridian');
181: MSite::getInstance()->addBodyAttribute('class', 'claro');
182:
183: }
184:
185: public function setUseSubmitButton($useSubmitButton)
186: {
187: $this->useSubmitButton = $useSubmitButton;
188: }
189:
190: public function setSubmitButtonText($submitButtonText)
191: {
192: $this->submitButtonText = $submitButtonText;
193: }
194:
195: public function setLabelWidthOnEachFormItem($labelWidth)
196: {
197:
198: foreach ($this->formItems as $formItem) {
199: $formItem->setLabelWidth($labelWidth);
200: $formItem->init();
201: }
202: }
203: }