1 <?php
2
3 4 5
6 abstract class rex_form_base
7 {
8
9 protected $name;
10
11
12 protected $method;
13
14
15 protected $fieldset;
16
17
18 protected $elements;
19
20
21 protected $params;
22
23
24 protected $debug;
25
26
27 protected $applyUrl;
28
29
30 protected $message;
31
32
33 protected $errorMessages;
34
35
36 protected $warning;
37
38
39 protected $formId;
40
41
42 private $csrfToken;
43
44 45 46
47 protected function __construct($fieldset, $name, $method = 'post', $debug = false)
48 {
49 if (!in_array($method, ['post', 'get'])) {
50 throw new InvalidArgumentException("rex_form: Method-Parameter darf nur die Werte 'post' oder 'get' annehmen!");
51 }
52
53 $this->name = $name;
54 $this->method = $method;
55 $this->elements = [];
56 $this->params = [];
57 $this->addFieldset($fieldset ?: $this->name);
58 $this->setMessage('');
59
60 $this->debug = $debug;
61
62 $this->csrfToken = rex_csrf_token::factory('rex_form_'.$this->getName());
63 }
64
65 66 67
68 public function init()
69 {
70
71 }
72
73 74 75
76 protected function loadBackendConfig()
77 {
78 $this->addParam('page', rex_be_controller::getCurrentPage());
79 }
80
81 public function setFormId($id)
82 {
83 $this->formId = $id;
84 }
85
86 87 88 89 90 91 92 93
94 public function getUrl(array $params = [], $escape = true)
95 {
96 $params = array_merge($this->getParams(), $params);
97 $params['form'] = $this->getName();
98
99 $url = rex::isBackend() ? rex_url::backendController($params, $escape) : rex_url::frontendController($params, $escape);
100
101 return $url;
102 }
103
104
105
106 107 108 109
110 public function addFieldset($fieldset)
111 {
112 $this->fieldset = $fieldset;
113 }
114
115
116
117 118 119 120 121 122 123 124 125 126 127
128 public function addField($tag, $name, $value = null, array $attributes = [], $addElement = true)
129 {
130 $element = $this->createElement($tag, $name, $value, $attributes);
131
132 if ($addElement) {
133 $this->addElement($element);
134 return $element;
135 }
136
137 return $element;
138 }
139
140 141 142 143 144 145 146 147 148 149 150
151 public function addContainerField($name, $value = null, array $attributes = [])
152 {
153 if (!isset($attributes['class'])) {
154 $attributes['class'] = 'rex-form-container';
155 }
156 $attributes['internal::fieldClass'] = 'rex_form_container_element';
157
158 $field = $this->addField('', $name, $value, $attributes, true);
159 return $field;
160 }
161
162 163 164 165 166 167 168 169 170 171 172
173 public function addInputField($type, $name, $value = null, array $attributes = [], $addElement = true)
174 {
175 $attributes['type'] = $type;
176 $field = $this->addField('input', $name, $value, $attributes, $addElement);
177 return $field;
178 }
179
180 181 182 183 184 185 186 187 188
189 public function addTextField($name, $value = null, array $attributes = [])
190 {
191 if (!isset($attributes['class'])) {
192 $attributes['class'] = 'form-control';
193 }
194 $field = $this->addInputField('text', $name, $value, $attributes);
195 return $field;
196 }
197
198 199 200 201 202 203 204 205 206 207
208 public function addReadOnlyTextField($name, $value = null, array $attributes = [])
209 {
210 $attributes['readonly'] = 'readonly';
211 if (!isset($attributes['class'])) {
212 $attributes['class'] = 'form-control';
213 }
214 $field = $this->addInputField('text', $name, $value, $attributes);
215 return $field;
216 }
217
218 219 220 221 222 223 224 225 226 227
228 public function addReadOnlyField($name, $value = null, array $attributes = [])
229 {
230 $attributes['internal::fieldSeparateEnding'] = true;
231 $attributes['internal::noNameAttribute'] = true;
232 if (!isset($attributes['class'])) {
233
234
235
236 $attributes['class'] = 'form-control-static';
237 }
238 $field = $this->addField('p', $name, $value, $attributes, true);
239 return $field;
240 }
241
242 243 244 245 246 247 248 249 250
251 public function addHiddenField($name, $value = null, array $attributes = [])
252 {
253 $field = $this->addInputField('hidden', $name, $value, $attributes, true);
254 return $field;
255 }
256
257 258 259 260 261 262 263 264 265 266
267 public function addCheckboxField($name, $value = null, array $attributes = [])
268 {
269 $attributes['internal::fieldClass'] = 'rex_form_checkbox_element';
270 $field = $this->addField('', $name, $value, $attributes);
271 return $field;
272 }
273
274 275 276 277 278 279 280 281 282 283
284 public function addRadioField($name, $value = null, array $attributes = [])
285 {
286 $attributes['internal::fieldClass'] = 'rex_form_radio_element';
287 $field = $this->addField('radio', $name, $value, $attributes);
288 return $field;
289 }
290
291 292 293 294 295 296 297 298 299
300 public function addTextAreaField($name, $value = null, array $attributes = [])
301 {
302 $attributes['internal::fieldSeparateEnding'] = true;
303 if (!isset($attributes['class'])) {
304 $attributes['class'] = 'form-control';
305 }
306 307 308 309 310
311 if (!isset($attributes['rows'])) {
312 $attributes['rows'] = 6;
313 }
314
315 $field = $this->addField('textarea', $name, $value, $attributes);
316 return $field;
317 }
318
319 320 321 322 323 324 325 326 327
328 public function addSelectField($name, $value = null, array $attributes = [])
329 {
330 $attributes['internal::fieldClass'] = 'rex_form_select_element';
331 if (!isset($attributes['class'])) {
332 $attributes['class'] = 'form-control';
333 }
334 $field = $this->addField('', $name, $value, $attributes, true);
335 return $field;
336 }
337
338 339 340 341 342 343 344 345 346 347 348 349
350 public function addMediaField($name, $value = null, array $attributes = [])
351 {
352 if (!rex_addon::get('mediapool')->isAvailable()) {
353 throw new rex_exception(__METHOD__ . '() needs "mediapool" addon!');
354 }
355 $attributes['internal::fieldClass'] = 'rex_form_widget_media_element';
356 $field = $this->addField('', $name, $value, $attributes, true);
357 return $field;
358 }
359
360 361 362 363 364 365 366 367 368 369 370 371
372 public function addMedialistField($name, $value = null, array $attributes = [])
373 {
374 if (!rex_addon::get('mediapool')->isAvailable()) {
375 throw new rex_exception(__METHOD__ . '() needs "mediapool" addon!');
376 }
377 $attributes['internal::fieldClass'] = 'rex_form_widget_medialist_element';
378 $field = $this->addField('', $name, $value, $attributes, true);
379 return $field;
380 }
381
382 383 384 385 386 387 388 389 390 391 392 393
394 public function addLinkmapField($name, $value = null, array $attributes = [])
395 {
396 if (!rex_addon::get('structure')->isAvailable()) {
397 throw new rex_exception(__METHOD__ . '() needs "structure" addon!');
398 }
399 $attributes['internal::fieldClass'] = 'rex_form_widget_linkmap_element';
400 $field = $this->addField('', $name, $value, $attributes, true);
401 return $field;
402 }
403
404 405 406 407 408 409 410 411 412 413 414 415
416 public function addLinklistField($name, $value = null, array $attributes = [])
417 {
418 if (!rex_addon::get('structure')->isAvailable()) {
419 throw new rex_exception(__METHOD__ . '() needs "structure" addon!');
420 }
421 $attributes['internal::fieldClass'] = 'rex_form_widget_linklist_element';
422 $field = $this->addField('', $name, $value, $attributes, true);
423 return $field;
424 }
425
426 427 428 429 430 431 432 433 434 435 436 437
438 public function addControlField($saveElement = null, $applyElement = null, $deleteElement = null, $resetElement = null, $abortElement = null)
439 {
440 $field = $this->addElement(new rex_form_control_element($this, $saveElement, $applyElement, $deleteElement, $resetElement, $abortElement));
441 return $field;
442 }
443
444 445 446 447 448 449 450
451 public function addRawField($html)
452 {
453 $field = $this->addElement(new rex_form_raw_element($html, $this));
454 return $field;
455 }
456
457 458 459
460 public function addErrorMessage($errorCode, $errorMessage)
461 {
462 $this->errorMessages[$errorCode] = $errorMessage;
463 }
464
465 466 467 468
469 public function addParam($name, $value)
470 {
471 $this->params[$name] = $value;
472 }
473
474 475 476 477 478
479 public function getParams()
480 {
481 return $this->params;
482 }
483
484 485 486 487 488 489 490 491 492
493 public function getParam($name, $default = null)
494 {
495 if (isset($this->params[$name])) {
496 return $this->params[$name];
497 }
498 return $default;
499 }
500
501 502 503 504 505 506 507
508 protected function addElement(rex_form_element $element)
509 {
510 $this->elements[$this->fieldset][] = $element;
511 return $element;
512 }
513
514 515 516 517 518 519 520 521 522 523
524 public function createInput($inputType, $name, $value = null, array $attributes = [])
525 {
526 $tag = self::getInputTagName($inputType);
527 $className = self::getInputClassName($inputType);
528 $attributes = array_merge(self::getInputAttributes($inputType), $attributes);
529 $attributes['internal::fieldClass'] = $className;
530
531 $element = $this->createElement($tag, $name, $value, $attributes);
532
533 return $element;
534 }
535
536 537 538 539 540 541 542 543 544 545
546 protected function createElement($tag, $name, $value, array $attributes = [])
547 {
548 $id = $this->getId($name);
549
550
551 $postValue = $this->elementPostValue($this->getFieldsetName(), $name);
552 if ($postValue !== null) {
553 $value = $postValue;
554 }
555
556
557 if ($value === null) {
558 $value = $this->getValue($name);
559 }
560
561 if (!isset($attributes['internal::useArraySyntax'])) {
562 $attributes['internal::useArraySyntax'] = true;
563 }
564
565
566 $fieldName = $name;
567 if ($attributes['internal::useArraySyntax'] === true) {
568 $name = $this->fieldset . '[' . $name . ']';
569 } elseif ($attributes['internal::useArraySyntax'] === false) {
570 $name = $this->fieldset . '_' . $name;
571 }
572 unset($attributes['internal::useArraySyntax']);
573
574 $class = 'rex_form_element';
575 if (isset($attributes['internal::fieldClass'])) {
576 $class = $attributes['internal::fieldClass'];
577 unset($attributes['internal::fieldClass']);
578 }
579
580 $separateEnding = false;
581 if (isset($attributes['internal::fieldSeparateEnding'])) {
582 $separateEnding = $attributes['internal::fieldSeparateEnding'];
583 unset($attributes['internal::fieldSeparateEnding']);
584 }
585
586 $internal_attr = ['name' => $name];
587 if (isset($attributes['internal::noNameAttribute'])) {
588 $internal_attr = [];
589 unset($attributes['internal::noNameAttribute']);
590 }
591
592
593
594
595 $attributes = array_merge(['id' => $id], $attributes, $internal_attr);
596 $element = new $class($tag, $this, $attributes, $separateEnding);
597 $element->setFieldName($fieldName);
598 $element->setValue($value);
599 return $element;
600 }
601
602 protected function getId($name)
603 {
604 return $this->fieldset . '_' . $name;
605 }
606
607 abstract protected function getValue($name);
608
609 610 611
612 public function setApplyUrl($url)
613 {
614 if (is_array($url)) {
615 $url = $this->getUrl($url, false);
616 }
617
618 $this->applyUrl = $url;
619 }
620
621
622
623 624 625 626 627 628 629
630 public static function getInputClassName($inputType)
631 {
632
633 $className = rex_extension::registerPoint(new rex_extension_point('REX_FORM_INPUT_CLASS', '', ['inputType' => $inputType]));
634
635 if ($className) {
636 return $className;
637 }
638
639 switch ($inputType) {
640 case 'control':
641 $className = 'rex_form_control_element';
642 break;
643 case 'checkbox':
644 $className = 'rex_form_checkbox_element';
645 break;
646 case 'radio':
647 $className = 'rex_form_radio_element';
648 break;
649 case 'select':
650 $className = 'rex_form_select_element';
651 break;
652 case 'media':
653 $className = 'rex_form_widget_media_element';
654 break;
655 case 'medialist':
656 $className = 'rex_form_widget_medialist_element';
657 break;
658 case 'link':
659 $className = 'rex_form_widget_linkmap_element';
660 break;
661 case 'linklist':
662 $className = 'rex_form_widget_linklist_element';
663 break;
664 case 'hidden':
665 case 'readonly':
666 case 'readonlytext':
667 case 'text':
668 case 'textarea':
669 $className = 'rex_form_element';
670 break;
671 default:
672 throw new rex_exception("Unexpected inputType '" . $inputType . "'!");
673 }
674
675 return $className;
676 }
677
678 679 680 681 682
683 public static function getInputTagName($inputType)
684 {
685
686 $inputTag = rex_extension::registerPoint(new rex_extension_point('REX_FORM_INPUT_TAG', '', ['inputType' => $inputType]));
687
688 if ($inputTag) {
689 return $inputTag;
690 }
691
692 switch ($inputType) {
693 case 'checkbox':
694 case 'hidden':
695 case 'radio':
696 case 'readonlytext':
697 case 'text':
698 return 'input';
699 case 'textarea':
700 return $inputType;
701 case 'readonly':
702 return 'p';
703 default:
704 $inputTag = '';
705 }
706 return $inputTag;
707 }
708
709 710 711 712 713
714 public static function getInputAttributes($inputType)
715 {
716
717 $inputAttr = rex_extension::registerPoint(new rex_extension_point('REX_FORM_INPUT_ATTRIBUTES', [], ['inputType' => $inputType]));
718
719 if ($inputAttr) {
720 return $inputAttr;
721 }
722
723 switch ($inputType) {
724 case 'checkbox':
725 case 'hidden':
726 case 'radio':
727 return [
728 'type' => $inputType,
729 ];
730 case 'select':
731 return [
732 'class' => 'form-control',
733 ];
734 case 'text':
735 return [
736 'type' => $inputType,
737 'class' => 'form-control',
738 ];
739 case 'textarea':
740 return [
741 'internal::fieldSeparateEnding' => true,
742 'class' => 'form-control',
743
744 'rows' => 6,
745 ];
746 case 'readonly':
747 return [
748 'internal::fieldSeparateEnding' => true,
749 'internal::noNameAttribute' => true,
750 'class' => 'form-control-static',
751 ];
752 case 'readonlytext':
753 return [
754 'type' => 'text',
755 'readonly' => 'readonly',
756 'class' => 'form-control-static',
757 ];
758 default:
759 $inputAttr = [];
760 }
761
762 return $inputAttr;
763 }
764
765
766
767 768 769 770 771
772 protected function (rex_form_element $element)
773 {
774 return $element->getTag() == 'input' && $element->getAttribute('type') == 'hidden';
775 }
776
777 778 779 780 781
782 protected function (rex_form_element $element)
783 {
784 return $this->isControlElement($element);
785 }
786
787 788 789 790 791
792 protected function isControlElement(rex_form_element $element)
793 {
794 return is_a($element, 'rex_form_control_element');
795 }
796
797 798 799 800 801
802 protected function isRawElement(rex_form_element $element)
803 {
804 return is_a($element, 'rex_form_raw_element');
805 }
806
807 808 809
810 protected function ()
811 {
812 $headerElements = [];
813 foreach ($this->elements as $fieldsetName => $fieldsetElementsArray) {
814 foreach ($fieldsetElementsArray as $element) {
815 if ($this->isHeaderElement($element)) {
816 $headerElements[] = $element;
817 }
818 }
819 }
820 return $headerElements;
821 }
822
823 824 825
826 protected function ()
827 {
828 $footerElements = [];
829 foreach ($this->elements as $fieldsetName => $fieldsetElementsArray) {
830 foreach ($fieldsetElementsArray as $element) {
831 if ($this->isFooterElement($element)) {
832 $footerElements[] = $element;
833 }
834 }
835 }
836 return $footerElements;
837 }
838
839 840 841
842 protected function getFieldsetName()
843 {
844 return $this->fieldset;
845 }
846
847 848 849
850 protected function getFieldsets()
851 {
852 $fieldsets = [];
853 foreach ($this->elements as $fieldsetName => $fieldsetElementsArray) {
854 $fieldsets[] = $fieldsetName;
855 }
856 return $fieldsets;
857 }
858
859 860 861
862 protected function getFieldsetElements()
863 {
864 $fieldsetElements = [];
865 foreach ($this->elements as $fieldsetName => $fieldsetElementsArray) {
866 $fieldsetElements[$fieldsetName] = [];
867
868 foreach ($fieldsetElementsArray as $element) {
869 if ($this->isHeaderElement($element)) {
870 continue;
871 }
872 if ($this->isFooterElement($element)) {
873 continue;
874 }
875
876 $fieldsetElements[$fieldsetName][] = $element;
877 }
878 }
879 return $fieldsetElements;
880 }
881
882 883 884
885 protected function getSaveElements()
886 {
887 $fieldsetElements = [];
888 foreach ($this->elements as $fieldsetName => $fieldsetElementsArray) {
889 $fieldsetElements[$fieldsetName] = [];
890
891 foreach ($fieldsetElementsArray as $key => $element) {
892 if ($this->isFooterElement($element)) {
893 continue;
894 }
895 if ($this->isRawElement($element)) {
896 continue;
897 }
898
899 $fieldsetElements[$fieldsetName][] = $element;
900 }
901 }
902 return $fieldsetElements;
903 }
904
905 906 907
908 protected function getControlElement()
909 {
910 foreach ($this->elements as $fieldsetName => $fieldsetElementsArray) {
911 foreach ($fieldsetElementsArray as $element) {
912 if ($this->isControlElement($element)) {
913 return $element;
914 }
915 }
916 }
917 $noElement = null;
918 return $noElement;
919 }
920
921 922 923 924 925 926
927 protected function getElement($fieldsetName, $elementName)
928 {
929 $normalizedName = rex_string::normalize($fieldsetName . '[' . $elementName . ']', '_', '[]');
930 $result = $this->_getElement($fieldsetName, $normalizedName);
931 return $result;
932 }
933
934 935 936 937 938 939
940 private function _getElement($fieldsetName, $elementName)
941 {
942 if (is_array($this->elements[$fieldsetName])) {
943 for ($i = 0; $i < count($this->elements[$fieldsetName]); ++$i) {
944 if ($this->elements[$fieldsetName][$i]->getAttribute('name') == $elementName) {
945 return $this->elements[$fieldsetName][$i];
946 }
947 }
948 }
949 $result = null;
950 return $result;
951 }
952
953 954 955
956 public function getName()
957 {
958 return $this->name;
959 }
960
961 public function setWarning($warning)
962 {
963 $this->warning = $warning;
964 }
965
966 967 968
969 public function getWarning()
970 {
971 $warning = rex_request($this->getName() . '_warning', 'string');
972 if ($this->warning != '') {
973 $warning .= "\n" . $this->warning;
974 }
975 return $warning;
976 }
977
978 public function setMessage($message)
979 {
980 $this->message = $message;
981 }
982
983 984 985
986 public function getMessage()
987 {
988 $message = rex_request($this->getName() . '_msg', 'string');
989 if ($this->message != '') {
990 $message .= "\n" . $this->message;
991 }
992 return $message;
993 }
994
995 996 997 998
999 protected function preView($fieldsetName, $fieldName, $fieldValue)
1000 {
1001 return $fieldValue;
1002 }
1003
1004 1005 1006 1007 1008
1009 public function fieldsetPostValues($fieldsetName)
1010 {
1011
1012 $normalizedFieldsetName = rex_string::normalize($fieldsetName, '_', '[]');
1013
1014 return rex_post($normalizedFieldsetName, 'array');
1015 }
1016
1017 1018 1019 1020 1021 1022 1023
1024 public function elementPostValue($fieldsetName, $fieldName, $default = null)
1025 {
1026 $fields = $this->fieldsetPostValues($fieldsetName);
1027
1028
1029 $normalizedFieldName = rex_string::normalize($fieldName, '_', '[]');
1030
1031 if (isset($fields[$normalizedFieldName])) {
1032 return $fields[$normalizedFieldName];
1033 }
1034
1035 return $default;
1036 }
1037
1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049
1050 protected function validate()
1051 {
1052 $messages = [];
1053
1054 if (!$this->csrfToken->isValid()) {
1055 $messages[] = rex_i18n::msg('csrf_token_invalid');
1056 }
1057
1058 foreach ($this->getSaveElements() as $fieldsetName => $fieldsetElements) {
1059 foreach ($fieldsetElements as $element) {
1060
1061
1062 if (strpos($element->getAttribute('class'), 'form-control-static') !== false) {
1063 continue;
1064 }
1065
1066 $validator = $element->getValidator();
1067 if (!$validator->isValid($element->getSaveValue())) {
1068 $messages[] = $validator->getMessage();
1069 }
1070 }
1071 }
1072 return empty($messages) ? true : implode('<br />', $messages);
1073 }
1074
1075 1076 1077
1078 protected function processPostValues()
1079 {
1080 $saveElements = $this->getSaveElements();
1081 foreach ($saveElements as $fieldsetName => $fieldsetElements) {
1082 foreach ($fieldsetElements as $key => $element) {
1083
1084 if (strpos($element->getAttribute('class'), 'form-control-static') !== false) {
1085 continue;
1086 }
1087
1088 $fieldName = $element->getFieldName();
1089 $fieldValue = $this->elementPostValue($fieldsetName, $fieldName);
1090
1091 $element->setValue($fieldValue);
1092 }
1093 }
1094 }
1095
1096 1097 1098 1099 1100
1101 abstract protected function save();
1102
1103 1104 1105
1106 protected function delete()
1107 {
1108 throw new BadMethodCallException('delete() is not implemented.');
1109 }
1110
1111 protected function redirect($listMessage = '', $listWarning = '', array $params = [])
1112 {
1113 if ($listMessage != '') {
1114 $listName = rex_request('list', 'string');
1115 $params[$listName . '_msg'] = $listMessage;
1116 }
1117
1118 if ($listWarning != '') {
1119 $listName = rex_request('list', 'string');
1120 $params[$listName . '_warning'] = $listWarning;
1121 }
1122
1123 $paramString = '';
1124 foreach ($params as $name => $value) {
1125 $paramString .= '&' . $name . '=' . $value;
1126 }
1127
1128 if ($this->debug) {
1129 echo 'redirect to: ' . $this->applyUrl . $paramString;
1130 exit();
1131 }
1132
1133 header('Location: ' . $this->applyUrl . $paramString);
1134 exit();
1135 }
1136
1137 1138 1139
1140 public function get()
1141 {
1142 $this->init();
1143
1144 rex_extension::registerPoint(new rex_extension_point('REX_FORM_GET', $this, [], true));
1145
1146 if (!$this->applyUrl) {
1147 $this->setApplyUrl($this->getUrl(['func' => ''], false));
1148 }
1149
1150 if (($controlElement = $this->getControlElement()) !== null) {
1151 if ($controlElement->saved()) {
1152 $this->processPostValues();
1153
1154
1155
1156 if (($result = $this->validate()) === true && ($result = $this->save()) === true) {
1157 $this->redirect(rex_i18n::msg('form_saved'));
1158 } elseif (is_int($result) && isset($this->errorMessages[$result])) {
1159 $this->setWarning($this->errorMessages[$result]);
1160 } elseif (is_string($result) && $result != '') {
1161 $this->setWarning($result);
1162 } else {
1163 $this->setWarning(rex_i18n::msg('form_save_error'));
1164 }
1165 } elseif ($controlElement->applied()) {
1166 $this->processPostValues();
1167
1168
1169
1170 if (($result = $this->validate()) === true && ($result = $this->save()) === true) {
1171 $this->setMessage(rex_i18n::msg('form_applied'));
1172 } elseif (is_int($result) && isset($this->errorMessages[$result])) {
1173 $this->setWarning($this->errorMessages[$result]);
1174 } elseif (is_string($result) && $result != '') {
1175 $this->setWarning($result);
1176 } else {
1177 $this->setWarning(rex_i18n::msg('form_save_error'));
1178 }
1179 } elseif ($controlElement->deleted()) {
1180
1181
1182 if (($result = $this->delete()) === true) {
1183 $this->redirect(rex_i18n::msg('form_deleted'));
1184 } elseif (is_string($result) && $result != '') {
1185 $this->setWarning($result);
1186 } else {
1187 $this->setWarning(rex_i18n::msg('form_delete_error'));
1188 }
1189 } elseif ($controlElement->resetted()) {
1190
1191
1192 $this->setMessage(rex_i18n::msg('form_resetted'));
1193 } elseif ($controlElement->aborted()) {
1194
1195
1196 $this->redirect(rex_i18n::msg('form_resetted'));
1197 }
1198 }
1199
1200 $actionParams = [];
1201 if ('get' == strtolower($this->method)) {
1202
1203 foreach ($this->getParams() as $name => $value) {
1204 $this->addHiddenField($name, $value, ['internal::useArraySyntax' => 'none']);
1205 }
1206 } else {
1207 $actionParams = $this->getParams();
1208 }
1209
1210 $s = "\n";
1211
1212 $warning = $this->getWarning();
1213 $message = $this->getMessage();
1214 if ($warning != '') {
1215 $s .= ' ' . rex_view::error($warning) . "\n";
1216 } elseif ($message != '') {
1217 $s .= ' ' . rex_view::success($message) . "\n";
1218 }
1219
1220 $i = 0;
1221 $addHeaders = true;
1222 $fieldsets = $this->getFieldsetElements();
1223 $last = count($fieldsets);
1224
1225 $id = '';
1226 if ($this->formId) {
1227 $id = ' id="'.rex_escape($this->formId).'"';
1228 }
1229
1230 $s .= '<form' . $id . ' action="' . rex_url::backendController($actionParams) . '" method="' . $this->method . '">' . "\n";
1231 foreach ($fieldsets as $fieldsetName => $fieldsetElements) {
1232 $s .= '<fieldset>' . "\n";
1233
1234 if ($fieldsetName != '' && $fieldsetName != $this->name) {
1235 $s .= '<legend>' . rex_escape($fieldsetName) . '</legend>' . "\n";
1236 }
1237
1238
1239 if ($i == 0 && $addHeaders) {
1240 foreach ($this->getHeaderElements() as $element) {
1241
1242 $element->setValue($this->preView($fieldsetName, $element->getFieldName(), $element->getValue()));
1243
1244 $s .= $element->formatElement();
1245 }
1246 $addHeaders = false;
1247 }
1248
1249 foreach ($fieldsetElements as $element) {
1250
1251 $element->setValue($this->preView($fieldsetName, $element->getFieldName(), $element->getValue()));
1252 $s .= $element->get();
1253 }
1254
1255
1256 if (($i + 1) == $last) {
1257 foreach ($this->getFooterElements() as $element) {
1258
1259 $element->setValue($this->preView($fieldsetName, $element->getFieldName(), $element->getValue()));
1260 $s .= $element->get();
1261 }
1262 }
1263
1264 $s .= '</fieldset>' . "\n";
1265
1266 ++$i;
1267 }
1268
1269 $s .= $this->csrfToken->getHiddenField() . "\n";
1270 $s .= '</form>' . "\n";
1271
1272 return $s;
1273 }
1274
1275 public function show()
1276 {
1277 echo $this->get();
1278 }
1279 }
1280