From d93485dc2371e0c589c2b0001f719c89fd71da4c Mon Sep 17 00:00:00 2001
From: Ralf Zimmermann <ralf.zimmermann@tritum.de>
Date: Tue, 29 Sep 2015 10:31:31 +0200
Subject: [PATCH] [BUGFIX] EXT:form - Bring back view specific layout settings

The issue #31951 introduced a solution for view specific layout settings
(for the form and the confirmation page). This patchset restores the
functionality and also allows a differing layout for the post processor/
mail. Furthermore it supports the extraordinary layout settings of
EXT:bootstrape_package which introduced some edge cases while changing
radiogroups and checkboxgroups.

Resolves: #70086
Releases: master
Change-Id: Ic8d1075e535a5ad7528ff53ddcf0daa44408d53d
Reviewed-on: http://review.typo3.org/43533
Tested-by: Bjoern Jacob <bjoern.jacob@tritum.de>
Reviewed-by: Bjoern Jacob <bjoern.jacob@tritum.de>
Reviewed-by: Frans Saris <franssaris@gmail.com>
Tested-by: Frans Saris <franssaris@gmail.com>
---
 .../Classes/Domain/Builder/FormBuilder.php    |  47 ++-
 .../Utility/CompatibilityLayerUtility.php     | 289 ++++++++++++++----
 .../ContainerElements/Checkboxgroup.html      |  45 ++-
 .../ContainerElements/Fieldset.html           |  45 ++-
 .../ContainerElements/Radiogroup.html         |  45 ++-
 .../Confirmation/FlatElements/Select.html     |   8 +-
 .../Html/ContainerElements/Checkboxgroup.html |  27 +-
 .../Mail/Html/ContainerElements/Fieldset.html |  27 +-
 .../Mail/Html/ContainerElements/Form.html     |  19 +-
 .../Html/ContainerElements/Radiogroup.html    |  27 +-
 .../Mail/Html/FlatElements/Checkbox.html      |  13 +-
 .../Mail/Html/FlatElements/Input.html         |   9 +-
 .../Mail/Html/FlatElements/Radio.html         |  11 +-
 .../Mail/Html/FlatElements/Select.html        |  43 ++-
 .../Mail/Html/FlatElements/Textarea.html      |   9 +-
 .../Mail/Html/FlatElements/Textfield.html     |   9 +-
 .../Mail/Html/FlatElements/Upload.html        |  11 +-
 .../Show/ContainerElements/Checkboxgroup.html |  37 ++-
 .../Show/ContainerElements/Fieldset.html      |  37 ++-
 .../Show/ContainerElements/Radiogroup.html    |  37 ++-
 20 files changed, 492 insertions(+), 303 deletions(-)

diff --git a/typo3/sysext/form/Classes/Domain/Builder/FormBuilder.php b/typo3/sysext/form/Classes/Domain/Builder/FormBuilder.php
index acc2727ad199..3a4616fa4aba 100644
--- a/typo3/sysext/form/Classes/Domain/Builder/FormBuilder.php
+++ b/typo3/sysext/form/Classes/Domain/Builder/FormBuilder.php
@@ -233,23 +233,38 @@ class FormBuilder {
 	public function buildModel() {
 		$userConfiguredFormTypoScript = $this->configuration->getTypoScript();
 
-		/**
-		 * The layout handling for the postProcessor is no longer supported
-		 **/
 		if ($this->configuration->getCompatibility()) {
-			/* use the compatibility theme whenever if a layout is defined */
-			if (
-				isset($userConfiguredFormTypoScript['layout.'])
-				|| isset($userConfiguredFormTypoScript['confirmation.']['layout.'])
-			) {
+			$layout = array();
+			if (isset($userConfiguredFormTypoScript['layout.'])) {
+				$layout = $userConfiguredFormTypoScript['layout.'];
+				/* use the compatibility theme whenever if a layout is defined */
 				$this->configuration->setThemeName(static::COMPATIBILITY_THEME_NAME);
-			}
-			if ($this->getControllerAction() === 'show') {
-				$this->compatibilityService->setGlobalLayoutConfiguration($userConfiguredFormTypoScript);
 				unset($userConfiguredFormTypoScript['layout.']);
-			} else if ($this->getControllerAction() === 'confirmation') {
-				$this->compatibilityService->setGlobalLayoutConfiguration($userConfiguredFormTypoScript['confirmation.']);
-				unset($userConfiguredFormTypoScript['confirmation.']['layout.']);
+			}
+
+			switch ($this->getControllerAction()) {
+				case 'show':
+					$actionLayoutKey = 'form.';
+					break;
+				case 'confirmation':
+					$actionLayoutKey = 'confirmation.';
+					break;
+				case 'process':
+					$actionLayoutKey = 'postProcessor.';
+					break;
+				default:
+					$actionLayoutKey = '';
+					break;
+			}
+			if ($actionLayoutKey && isset($userConfiguredFormTypoScript[$actionLayoutKey]['layout.'])) {
+				$actionLayout = $userConfiguredFormTypoScript[$actionLayoutKey]['layout.'];
+				$this->configuration->setThemeName(static::COMPATIBILITY_THEME_NAME);
+				unset($userConfiguredFormTypoScript[$actionLayoutKey]['layout.']);
+				$layout = array_replace_recursive($layout, $actionLayout);
+			}
+
+			if (!empty($layout)) {
+				$this->compatibilityService->setGlobalLayoutConfiguration($layout);
 			}
 		}
 
@@ -281,6 +296,10 @@ class FormBuilder {
 	protected function reviveElement(Element $element, array $userConfiguredElementTypoScript, $elementType = '') {
 		// @todo Check $userConfiguredElementTypoScript
 
+		if ($elementType === 'IMAGEBUTTON') {
+			GeneralUtility::deprecationLog('EXT:form: The element IMAGEBUTTON is deprecated since TYPO3 CMS 7, will be removed with TYPO3 CMS 8.');
+		}
+
 		$element->setElementType($elementType);
 		$element->setElementCounter($this->elementCounter);
 
diff --git a/typo3/sysext/form/Classes/Utility/CompatibilityLayerUtility.php b/typo3/sysext/form/Classes/Utility/CompatibilityLayerUtility.php
index 8a6c842c4b07..3fbd7d143742 100644
--- a/typo3/sysext/form/Classes/Utility/CompatibilityLayerUtility.php
+++ b/typo3/sysext/form/Classes/Utility/CompatibilityLayerUtility.php
@@ -101,18 +101,12 @@ class CompatibilityLayerUtility {
 	/**
 	 * Set the layout configuration for one or more elements
 	 *
-	 * @param NULL|array $typoscript The configuration array
+	 * @param NULL|array $layout The configuration array
 	 * @return void
 	 * @deprecated since TYPO3 CMS 7, this function will be removed in TYPO3 CMS 8, as the functionality is now done via fluid
 	 */
-	public function setGlobalLayoutConfiguration($typoscript = array()) {
-		if (!empty($typoscript['layout.'])) {
-			GeneralUtility::deprecationLog('EXT:form: Do not use "layout." anymore. Deprecated since TYPO3 CMS 7, this function will be removed in TYPO3 CMS 8.');
-			$layout = $typoscript['layout.'];
-		} else if (!empty($typoscript['layout'])) {
-			GeneralUtility::deprecationLog('EXT:form: Do not use "layout." anymore. Deprecated since TYPO3 CMS 7, this function will be removed in TYPO3 CMS 8.');
-			$layout = $typoscript['layout'];
-		}
+	public function setGlobalLayoutConfiguration($layout = array()) {
+		GeneralUtility::deprecationLog('EXT:form: Do not use "layout." anymore. Deprecated since TYPO3 CMS 7, this function will be removed in TYPO3 CMS 8.');
 		if (is_array($layout)) {
 			foreach ($layout as $elementType => $elementValue) {
 				$elementType = strtoupper($elementType);
@@ -136,47 +130,115 @@ class CompatibilityLayerUtility {
 		if (!empty($this->layout[$elementType])) {
 			$layout = $this->layout[$elementType];
 		} else {
+			$action = $this->formBuilder->getControllerAction();
 			switch ($elementType) {
 				case 'FORM':
 					$layout = '<form><containerWrap /></form>';
 					break;
+				case 'CONFIRMATION':
+					$layout = '<containerWrap />';
+					break;
+				case 'HTML':
+					$layout = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body><table cellspacing="0"><containerWrap /></table></body></html>';
+					break;
 				case 'CONTAINERWRAP':
-					$layout = '<ol><elements /></ol>';
+					if ($action !== 'process') {
+						$layout = '<ol><elements /></ol>';
+					} else {
+						$layout = '<tbody><elements /></tbody>';
+					}
 					break;
 				case 'ELEMENTWRAP':
-					$layout = '<li><element /></li>';
+					if ($action !== 'process') {
+						$layout = '<li><element /></li>';
+					} else {
+						$layout = '<tr><element /></tr>';
+					}
 					break;
 				case 'LABEL':
-					$layout = '<label><labelvalue /><mandatory /><error /></label>';
+					if ($action === 'show') {
+						$layout = '<label><labelvalue /><mandatory /><error /></label>';
+					} else if ($action === 'confirmation') {
+						$layout = '<label><labelvalue /></label>';
+					} else {
+						$layout = '<em><labelvalue /></em>';
+					}
+					break;
+				case 'LEGEND':
+					if ($action !== 'process') {
+						$layout = '<legend><legendvalue /></legend>';
+					} else {
+						$layout = '<thead><tr><th colspan="2" align="left"><legendvalue /></th></tr></thead>';
+					}
 					break;
 				case 'MANDATORY':
-					$layout = '<em><mandatoryvalue /></em>';
+					if ($action !== 'process') {
+						$layout = '<em><mandatoryvalue /></em>';
+					} else {
+						$layout = '';
+					}
 					break;
 				case 'ERROR':
-					$layout = '<strong><errorvalue /></strong>';
+					if ($action !== 'process') {
+						$layout = '<strong><errorvalue /></strong>';
+					} else {
+						$layout = '';
+					}
 					break;
+				case 'RADIOGROUP':
+				case 'CHECKBOXGROUP':
 				case 'FIELDSET':
-					$layout = '<fieldset><legend /><containerWrap /></fieldset>';
+					if ($action !== 'process') {
+						$layout = '<fieldset><legend /><containerWrap /></fieldset>';
+					} else {
+						$layout = '<td colspan="2"><table cellspacing="0" style="padding-left: 20px; margin-bottom: 20px;"><legend /><containerWrap /></table></td>';
+					}
 					break;
 				case 'HIDDEN':
-					$layout = '<input />';
+					if ($action !== 'process') {
+						$layout = '<input />';
+					} else {
+						$layout = '';
+					}
 					break;
 				case 'SELECT':
-					$layout = '<label /><select><elements /></select>';
+					if ($action === 'show') {
+						$layout = '<label /><select><elements /></select>';
+					} else if ($action === 'confirmation') {
+						$layout = '<label /><ol><elements /></ol>';
+					} else {
+						$layout = '<td style="width: 200px;"><label /></td><td><elements /></td>';
+					}
 					break;
 				case 'TEXTAREA':
-					$layout = '<label /><textarea />';
+					if ($action === 'show') {
+						$layout = '<label /><textarea />';
+					} else if ($action === 'confirmation') {
+						$layout = '<label /><inputvalue />';
+					} else {
+						$layout = '<td style="width: 200px;" valign="top"><label /></td><td><inputvalue /></td>';
+					}
 					break;
 				case 'BUTTON':
-				case 'CHECKBOX':
-				case 'FILEUPLOAD':
 				case 'IMAGEBUTTON':
 				case 'PASSWORD':
-				case 'RADIO':
 				case 'RESET':
 				case 'SUBMIT':
+					if ($action !== 'show') {
+						$layout = '';
+						break;
+					}
+				case 'CHECKBOX':
+				case 'FILEUPLOAD':
+				case 'RADIO':
 				case 'TEXTLINE':
-					$layout = '<label /><input />';
+					if ($action === 'show') {
+						$layout = '<label /><input />';
+					} else if ($action === 'confirmation') {
+						$layout = '<label /><inputvalue />';
+					} else {
+						$layout = '<td style="width: 200px;"><label /></td><td><inputvalue /></td>';
+					}
 					break;
 			}
 		}
@@ -196,7 +258,13 @@ class CompatibilityLayerUtility {
 		GeneralUtility::deprecationLog('EXT:form: Do not use "layout." anymore. Deprecated since TYPO3 CMS 7, this function will be removed in TYPO3 CMS 8.');
 		if ($element->getElementType() === 'FORM') {
 			$containerWrapReturn = $this->replaceTagWithMarker('elements', 'body', $this->getGlobalLayoutByElementType('CONTAINERWRAP'));
-			$formWrapReturn = $this->replaceTagWithMarker('containerwrap', 'form', $this->getGlobalLayoutByElementType('FORM'));
+			if ($this->formBuilder->getControllerAction() === 'show') {
+				$formWrapReturn = $this->replaceTagWithMarker('containerwrap', 'form', $this->getGlobalLayoutByElementType('FORM'));
+			} else if ($this->formBuilder->getControllerAction() === 'confirmation') {
+				$formWrapReturn = $this->replaceTagWithMarker('containerwrap', 'body', $this->getGlobalLayoutByElementType('CONFIRMATION'));
+			} else {
+				$formWrapReturn = $this->replaceTagWithMarker('containerwrap', 'html', $this->getGlobalLayoutByElementType('HTML'));
+			}
 			$formLayout = str_replace($formWrapReturn['marker'], $containerWrapReturn['html'], $formWrapReturn['html']);
 			$formContainerWrap = explode($containerWrapReturn['marker'], $formLayout);
 			$layout['containerInnerWrap'] = $formContainerWrap;
@@ -265,6 +333,22 @@ class CompatibilityLayerUtility {
 						}
 						if (!$labelContainContent) {
 							$labelLayout = '';
+						} else {
+							$libxmlUseInternalErrors = libxml_use_internal_errors(true);
+							$dom = new \DOMDocument('1.0', 'utf-8');
+							$dom->formatOutput = TRUE;
+							$dom->preserveWhiteSpace = FALSE;
+							if ($dom->loadXML($labelLayout)) {
+								$nodes = $dom->getElementsByTagName('label');
+								if ($nodes->length) {
+									$node = $nodes->item(0);
+									if ($node) {
+										$node->setAttribute('for', $element->getId());
+										$labelLayout = $dom->saveXML($dom->firstChild);
+									}
+								}
+							}
+							libxml_use_internal_errors($libxmlUseInternalErrors);
 						}
 						/* Replace <label />, <error /> and <mandatory /> in the element wrap html */
 						$labelReturn = $this->replaceTagWithMarker('label', 'body', $elementWrap['html']);
@@ -288,13 +372,14 @@ class CompatibilityLayerUtility {
 			/* Set element outer wraps and set the default classes */
 			$elementOuterWrap = NULL;
 			if ($this->getGlobalLayoutByElementType('ELEMENTWRAP')) {
+				$libxmlUseInternalErrors = libxml_use_internal_errors(true);
 				$dom = new \DOMDocument('1.0', 'utf-8');
 				$dom->formatOutput = TRUE;
 				$dom->preserveWhiteSpace = FALSE;
-				$dom->loadXML($this->getGlobalLayoutByElementType('ELEMENTWRAP'));
-				if ($dom) {
+				if ($dom->loadXML($this->getGlobalLayoutByElementType('ELEMENTWRAP'))) {
 					$node = $dom->firstChild;
 					if ($node) {
+						$class = '';
 						if ($node->getAttribute('class') !== '') {
 							$class = $node->getAttribute('class') . ' ';
 						}
@@ -304,6 +389,11 @@ class CompatibilityLayerUtility {
 						$return = $this->replaceTagWithMarker('element', 'body', $elementOuterWrap);
 						if ($return['marker'] !== '') {
 							$elementOuterWrap = explode($return['marker'], $return['html']);
+							if ($element->getElementType() === 'SELECT') {
+								$layout = $element->getLayout();
+								$layout['optionOuterWrap'] = $elementOuterWrap;
+								$element->setLayout($layout);
+							}
 						} else {
 							/* this should never be happen */
 							$elementOuterWrap = NULL;
@@ -312,7 +402,9 @@ class CompatibilityLayerUtility {
 				} else {
 					$elementOuterWrap = NULL;
 				}
+				libxml_use_internal_errors($libxmlUseInternalErrors);
 			}
+
 			if (
 				$elementWrap
 				&& !$elementOuterWrap
@@ -345,25 +437,77 @@ class CompatibilityLayerUtility {
 			/* Set container inner wraps */
 			if (in_array($element->getElementType(), $this->containerElements)) {
 				$elementWrap = $this->determineElementOuterWraps($element->getElementType(), $elementLayout);
-				$containerOuterWrap = array('', '');
-				if ($elementWrap['marker'] !== '') {
-					$containerOuterWrap = explode($elementWrap['marker'], $elementWrap['html']);
+				/* Replace the legend value */
+				$legendLayout = $this->getGlobalLayoutByElementType('LEGEND');
+				$legendValueReturn = $this->replaceTagWithMarker('legendvalue', 'body', $legendLayout);
+				$legendContainContent = FALSE;
+				if ($legendValueReturn['html'] !== '') {
+					if (!empty($element->getAdditionalArgument('legend'))) {
+						$legendContainContent = TRUE;
+					}
+					$legendLayout = str_replace($legendValueReturn['marker'], $element->getAdditionalArgument('legend'), $legendValueReturn['html']);
 				}
-				$containerWrapReturn = $this->replaceTagWithMarker('elements', 'body', $this->getGlobalLayoutByElementType('CONTAINERWRAP'));
-				$containerInnerWrap = explode($containerWrapReturn['marker'], $containerWrapReturn['html']);
-				$containerWrap = array(
-					$containerOuterWrap[0] . $containerInnerWrap[0],
-					$containerInnerWrap[1] . $containerOuterWrap[1],
-				);
-				$layout = $element->getLayout();
-				$layout['containerInnerWrap'] = $containerWrap;
-				$element->setLayout($layout);
-				$classFromLayout = $this->getElementClassFromLayout('fieldset');
-				if (!empty($classFromLayout)) {
-					if (!empty($element->getHtmlAttribute('class'))) {
-						$classFromLayout .= ' ' . $element->getHtmlAttribute('class');
+				/* remove <mandatory /> and <error /> from legend */
+				$mandatoryReturn = $this->replaceTagWithMarker('mandatory', 'body', $legendLayout);
+				if (!empty($mandatoryReturn['html'])) {
+					$legendLayout = str_replace($mandatoryReturn['marker'], '', $mandatoryReturn['html']);
+				}
+				$errorReturn = $this->replaceTagWithMarker('error', 'body', $legendLayout);
+				if (!empty($errorReturn['html'])) {
+					$legendLayout = str_replace($errorReturn['marker'], '', $errorReturn['html']);
+				}
+
+				if (!$legendContainContent) {
+					$legendLayout = '';
+				}
+				/* No fieldset tag exist.
+				 * Ignore CONTAINERWRAP
+				 * */
+				if ($elementWrap['html'] === '') {
+					$containerWrapReturn = $this->replaceTagWithMarker('elements', 'body', $elementLayout);
+					$legendReturn = $this->replaceTagWithMarker('legend', 'body', $containerWrapReturn['html']);
+
+					if ($legendReturn['html'] !== '') {
+						$containerWrapReturn['html'] = str_replace($legendReturn['marker'], $legendLayout, $legendReturn['html']);
+					}
+					if ($containerWrapReturn['marker'] && $containerWrapReturn['html']) {
+						$containerWrap = explode($containerWrapReturn['marker'], $containerWrapReturn['html']);
+					} else {
+						$containerWrap = array('', '');
+					}
+
+					$layout = $element->getLayout();
+					$layout['containerInnerWrap'] = $containerWrap;
+					$layout['noFieldsetTag'] = TRUE;
+					$element->setLayout($layout);
+				} else {
+					$legendReturn = $this->replaceTagWithMarker('legend', 'body', $elementWrap['html']);
+
+					if ($legendReturn['html'] !== '') {
+						$elementWrap['html'] = str_replace($legendReturn['marker'], $legendLayout, $legendReturn['html']);
+					}
+
+					/* set the wraps */
+					$containerOuterWrap = array('', '');
+					$containerOuterWrap = explode($elementWrap['marker'], $elementWrap['html']);
+					$containerWrapReturn = $this->replaceTagWithMarker('elements', 'body', $this->getGlobalLayoutByElementType('CONTAINERWRAP'));
+					$containerInnerWrap = explode($containerWrapReturn['marker'], $containerWrapReturn['html']);
+
+					$containerWrap = array(
+						$containerOuterWrap[0] . $containerInnerWrap[0],
+						$containerInnerWrap[1] . $containerOuterWrap[1],
+					);
+
+					$layout = $element->getLayout();
+					$layout['containerInnerWrap'] = $containerWrap;
+					$element->setLayout($layout);
+					$classFromLayout = $this->getElementClassFromLayout('fieldset');
+					if (!empty($classFromLayout)) {
+						if (!empty($element->getHtmlAttribute('class'))) {
+							$classFromLayout .= ' ' . $element->getHtmlAttribute('class');
+						}
+						$element->setHtmlAttribute('class', $classFromLayout);
 					}
-					$element->setHtmlAttribute('class', $classFromLayout);
 				}
 			}
 			return;
@@ -415,20 +559,37 @@ class CompatibilityLayerUtility {
 	 * outer wrapping
 	 *
 	 * @param string $elementType
-	 * @return string $elementLayout
+	 * @param string $elementLayout
+	 * @return string
 	 * @deprecated since TYPO3 CMS 7, this function will be removed in TYPO3 CMS 8, as the functionality is now done via fluid
 	 */
 	protected function determineElementOuterWraps($elementType, $elementLayout = '') {
-		if ($elementType === 'TEXTAREA') {
-			$return = $this->replaceTagWithMarker('textarea', 'body', $elementLayout);
-		} elseif ($elementType === 'CONTENTELEMENT') {
-			$return = $this->replaceTagWithMarker('content', 'body', $elementLayout);
-		} elseif ($elementType === 'SELECT') {
-			$return = $this->replaceTagWithMarker('select', 'body', $elementLayout);
-		} elseif (in_array($elementType, $this->containerElements)) {
-			$return = $this->replaceTagWithMarker('fieldset', 'body', $elementLayout);
+		if ($this->formBuilder->getControllerAction() === 'show') {
+			if ($elementType === 'TEXTAREA') {
+				$return = $this->replaceTagWithMarker('textarea', 'body', $elementLayout);
+			} elseif ($elementType === 'CONTENTELEMENT') {
+				$return = $this->replaceTagWithMarker('content', 'body', $elementLayout);
+			} elseif ($elementType === 'SELECT') {
+				$return = $this->replaceTagWithMarker('select', 'body', $elementLayout);
+			} elseif (in_array($elementType, $this->containerElements)) {
+				$return = $this->replaceTagWithMarker('fieldset', 'body', $elementLayout);
+			} else {
+				$return = $this->replaceTagWithMarker('input', 'body', $elementLayout);
+			}
 		} else {
-			$return = $this->replaceTagWithMarker('input', 'body', $elementLayout);
+			if ($elementType === 'CONTENTELEMENT') {
+				$return = $this->replaceTagWithMarker('content', 'body', $elementLayout);
+			} elseif ($elementType === 'SELECT') {
+				$return = $this->replaceTagWithMarker('elements', 'body', $elementLayout);
+			} elseif (in_array($elementType, $this->containerElements)) {
+				if ($this->formBuilder->getControllerAction() === 'confirmation') {
+					$return = $this->replaceTagWithMarker('fieldset', 'body', $elementLayout);
+				} else {
+					$return = $this->replaceTagWithMarker('containerwrap', 'body', $elementLayout);
+				}
+			} else {
+				$return = $this->replaceTagWithMarker('inputvalue', 'body', $elementLayout);
+			}
 		}
 		return $return;
 	}
@@ -451,17 +612,17 @@ class CompatibilityLayerUtility {
 				'marker' => ''
 			);
 		}
-		libxml_use_internal_errors(true);
+		$libxmlUseInternalErrors = libxml_use_internal_errors(true);
 		$dom = new \DOMDocument('1.0', 'utf-8');
 		$dom->preserveWhiteSpace = FALSE;
-		$dom->loadHTML($html);
-		libxml_use_internal_errors(false);
-		if (!$dom) {
+		if (!$dom->loadHTML($html)) {
+			libxml_use_internal_errors($libxmlUseInternalErrors);
 			return array(
 				'html' => '',
 				'marker' => ''
 			);
 		}
+		libxml_use_internal_errors($libxmlUseInternalErrors);
 		$nodes = $dom->getElementsByTagName($tagName);
 		if (!$nodes->length) {
 			return array(
@@ -487,13 +648,19 @@ class CompatibilityLayerUtility {
 			}
 			$nextParent = $nextParent->parentNode;
 		}
-		$children = $nextParent->childNodes;
-		$innerHtml = '';
-		foreach ($children as $child) {
-			$innerHtml .= $nextParent->ownerDocument->saveHTML($child);
+		$html = '';
+		/* if stopTag == html, save the whole html */
+		if ($stopTag === 'html') {
+			$html = $nextParent->ownerDocument->saveHTML($nextParent);
+		} else {
+			/* do not save the stopTag */
+			$children = $nextParent->childNodes;
+			foreach ($children as $child) {
+				$html .= $nextParent->ownerDocument->saveHTML($child);
+			}
 		}
 		return array(
-			'html' => $innerHtml,
+			'html' => $html,
 			'marker' => $marker
 		);
 	}
diff --git a/typo3/sysext/form/Resources/Private/Partials/Compatibility/Confirmation/ContainerElements/Checkboxgroup.html b/typo3/sysext/form/Resources/Private/Partials/Compatibility/Confirmation/ContainerElements/Checkboxgroup.html
index 555130e9d7e2..737ee03e4a9f 100644
--- a/typo3/sysext/form/Resources/Private/Partials/Compatibility/Confirmation/ContainerElements/Checkboxgroup.html
+++ b/typo3/sysext/form/Resources/Private/Partials/Compatibility/Confirmation/ContainerElements/Checkboxgroup.html
@@ -1,23 +1,36 @@
 <f:if condition="{model.additionalArguments.atLeastOneCheckedChildElement}">
 	<f:if condition="{model.showElement}">
 		<f:then>
-			<f:format.raw>{model.layout.elementOuterWrap.0}</f:format.raw>
-				<fieldset
-				<f:for each="{model.htmlAttributes}" as="htmAttributeValue" key="htmAttributeKey">
-					{htmAttributeKey}="{htmAttributeValue}"
-				</f:for>
-				>
-				<f:if condition="{model.additionalArguments.legend}">
-					<legend>{model.additionalArguments.legend}</legend>
-				</f:if>
+			<f:if condition="{model.layout.noFieldsetTag}">
+				<f:then>
+					<f:format.raw>{model.layout.elementOuterWrap.0}</f:format.raw>
+					<f:format.raw>{model.layout.containerInnerWrap.0}</f:format.raw>
+						<f:for each="{model.childElements}" as="element">
+							<f:render partial="{themeName}/Confirmation/{element.partialPath}" arguments="{model: element, themeName: themeName}" />
+						</f:for>
+					<f:format.raw>{model.layout.containerInnerWrap.1}</f:format.raw>
+					<f:format.raw>{model.layout.elementOuterWrap.1}</f:format.raw>
+				</f:then>
+				<f:else>
+					<f:format.raw>{model.layout.elementOuterWrap.0}</f:format.raw>
+						<fieldset
+						<f:for each="{model.htmlAttributes}" as="htmAttributeValue" key="htmAttributeKey">
+							{htmAttributeKey}="{htmAttributeValue}"
+						</f:for>
+						>
+							<f:if condition="{model.additionalArguments.legend}">
+								<legend>{model.additionalArguments.legend}</legend>
+							</f:if>
 
-				<f:format.raw>{model.layout.containerInnerWrap.0}</f:format.raw>
-					<f:for each="{model.childElements}" as="element">
-						<f:render partial="{themeName}/Confirmation/{element.partialPath}" arguments="{model: element, themeName: themeName}" />
-					</f:for>
-				<f:format.raw>{model.layout.containerInnerWrap.1}</f:format.raw>
-			</fieldset>
-			<f:format.raw>{model.layout.elementOuterWrap.1}</f:format.raw>
+							<f:format.raw>{model.layout.containerInnerWrap.0}</f:format.raw>
+								<f:for each="{model.childElements}" as="element">
+									<f:render partial="{themeName}/Confirmation/{element.partialPath}" arguments="{model: element, themeName: themeName}" />
+								</f:for>
+							<f:format.raw>{model.layout.containerInnerWrap.1}</f:format.raw>
+						</fieldset>
+					<f:format.raw>{model.layout.elementOuterWrap.1}</f:format.raw>
+				</f:else>
+			</f:if>
 		</f:then>
 		<f:else>
 			<f:for each="{model.childElements}" as="element">
diff --git a/typo3/sysext/form/Resources/Private/Partials/Compatibility/Confirmation/ContainerElements/Fieldset.html b/typo3/sysext/form/Resources/Private/Partials/Compatibility/Confirmation/ContainerElements/Fieldset.html
index d52bbbfc0177..dc7cb8ab835d 100644
--- a/typo3/sysext/form/Resources/Private/Partials/Compatibility/Confirmation/ContainerElements/Fieldset.html
+++ b/typo3/sysext/form/Resources/Private/Partials/Compatibility/Confirmation/ContainerElements/Fieldset.html
@@ -1,23 +1,36 @@
 <f:if condition="{model.childElements.0}">
 	<f:if condition="{model.showElement}">
 		<f:then>
-			<f:format.raw>{model.layout.elementOuterWrap.0}</f:format.raw>
-			<fieldset
-				<f:for each="{model.htmlAttributes}" as="htmAttributeValue" key="htmAttributeKey">
-					{htmAttributeKey}="{htmAttributeValue}"
-				</f:for>
-				>
-				<f:if condition="{model.additionalArguments.legend}">
-					<legend>{model.additionalArguments.legend}</legend>
-				</f:if>
+			<f:if condition="{model.layout.noFieldsetTag}">
+				<f:then>
+					<f:format.raw>{model.layout.elementOuterWrap.0}</f:format.raw>
+					<f:format.raw>{model.layout.containerInnerWrap.0}</f:format.raw>
+						<f:for each="{model.childElements}" as="element">
+							<f:render partial="{themeName}/Confirmation/{element.partialPath}" arguments="{model: element, themeName: themeName}" />
+						</f:for>
+					<f:format.raw>{model.layout.containerInnerWrap.1}</f:format.raw>
+					<f:format.raw>{model.layout.elementOuterWrap.1}</f:format.raw>
+				</f:then>
+				<f:else>
+					<f:format.raw>{model.layout.elementOuterWrap.0}</f:format.raw>
+						<fieldset
+						<f:for each="{model.htmlAttributes}" as="htmAttributeValue" key="htmAttributeKey">
+							{htmAttributeKey}="{htmAttributeValue}"
+						</f:for>
+						>
+							<f:if condition="{model.additionalArguments.legend}">
+								<legend>{model.additionalArguments.legend}</legend>
+							</f:if>
 
-				<f:format.raw>{model.layout.containerInnerWrap.0}</f:format.raw>
-					<f:for each="{model.childElements}" as="element">
-						<f:render partial="{themeName}/Confirmation/{element.partialPath}" arguments="{model: element, themeName: themeName}" />
-					</f:for>
-				<f:format.raw>{model.layout.containerInnerWrap.1}</f:format.raw>
-			</fieldset>
-		<f:format.raw>{model.layout.elementOuterWrap.1}</f:format.raw>
+							<f:format.raw>{model.layout.containerInnerWrap.0}</f:format.raw>
+								<f:for each="{model.childElements}" as="element">
+									<f:render partial="{themeName}/Confirmation/{element.partialPath}" arguments="{model: element, themeName: themeName}" />
+								</f:for>
+							<f:format.raw>{model.layout.containerInnerWrap.1}</f:format.raw>
+						</fieldset>
+					<f:format.raw>{model.layout.elementOuterWrap.1}</f:format.raw>
+				</f:else>
+			</f:if>
 		</f:then>
 		<f:else>
 			<f:for each="{model.childElements}" as="element">
diff --git a/typo3/sysext/form/Resources/Private/Partials/Compatibility/Confirmation/ContainerElements/Radiogroup.html b/typo3/sysext/form/Resources/Private/Partials/Compatibility/Confirmation/ContainerElements/Radiogroup.html
index 555130e9d7e2..737ee03e4a9f 100644
--- a/typo3/sysext/form/Resources/Private/Partials/Compatibility/Confirmation/ContainerElements/Radiogroup.html
+++ b/typo3/sysext/form/Resources/Private/Partials/Compatibility/Confirmation/ContainerElements/Radiogroup.html
@@ -1,23 +1,36 @@
 <f:if condition="{model.additionalArguments.atLeastOneCheckedChildElement}">
 	<f:if condition="{model.showElement}">
 		<f:then>
-			<f:format.raw>{model.layout.elementOuterWrap.0}</f:format.raw>
-				<fieldset
-				<f:for each="{model.htmlAttributes}" as="htmAttributeValue" key="htmAttributeKey">
-					{htmAttributeKey}="{htmAttributeValue}"
-				</f:for>
-				>
-				<f:if condition="{model.additionalArguments.legend}">
-					<legend>{model.additionalArguments.legend}</legend>
-				</f:if>
+			<f:if condition="{model.layout.noFieldsetTag}">
+				<f:then>
+					<f:format.raw>{model.layout.elementOuterWrap.0}</f:format.raw>
+					<f:format.raw>{model.layout.containerInnerWrap.0}</f:format.raw>
+						<f:for each="{model.childElements}" as="element">
+							<f:render partial="{themeName}/Confirmation/{element.partialPath}" arguments="{model: element, themeName: themeName}" />
+						</f:for>
+					<f:format.raw>{model.layout.containerInnerWrap.1}</f:format.raw>
+					<f:format.raw>{model.layout.elementOuterWrap.1}</f:format.raw>
+				</f:then>
+				<f:else>
+					<f:format.raw>{model.layout.elementOuterWrap.0}</f:format.raw>
+						<fieldset
+						<f:for each="{model.htmlAttributes}" as="htmAttributeValue" key="htmAttributeKey">
+							{htmAttributeKey}="{htmAttributeValue}"
+						</f:for>
+						>
+							<f:if condition="{model.additionalArguments.legend}">
+								<legend>{model.additionalArguments.legend}</legend>
+							</f:if>
 
-				<f:format.raw>{model.layout.containerInnerWrap.0}</f:format.raw>
-					<f:for each="{model.childElements}" as="element">
-						<f:render partial="{themeName}/Confirmation/{element.partialPath}" arguments="{model: element, themeName: themeName}" />
-					</f:for>
-				<f:format.raw>{model.layout.containerInnerWrap.1}</f:format.raw>
-			</fieldset>
-			<f:format.raw>{model.layout.elementOuterWrap.1}</f:format.raw>
+							<f:format.raw>{model.layout.containerInnerWrap.0}</f:format.raw>
+								<f:for each="{model.childElements}" as="element">
+									<f:render partial="{themeName}/Confirmation/{element.partialPath}" arguments="{model: element, themeName: themeName}" />
+								</f:for>
+							<f:format.raw>{model.layout.containerInnerWrap.1}</f:format.raw>
+						</fieldset>
+					<f:format.raw>{model.layout.elementOuterWrap.1}</f:format.raw>
+				</f:else>
+			</f:if>
 		</f:then>
 		<f:else>
 			<f:for each="{model.childElements}" as="element">
diff --git a/typo3/sysext/form/Resources/Private/Partials/Compatibility/Confirmation/FlatElements/Select.html b/typo3/sysext/form/Resources/Private/Partials/Compatibility/Confirmation/FlatElements/Select.html
index 772230c7f289..a2391a1ab26c 100644
--- a/typo3/sysext/form/Resources/Private/Partials/Compatibility/Confirmation/FlatElements/Select.html
+++ b/typo3/sysext/form/Resources/Private/Partials/Compatibility/Confirmation/FlatElements/Select.html
@@ -10,9 +10,7 @@
 						<f:for each="{option.options}" as="optgroupOption">
 							<f:if condition="{optgroupOption.selected}">
 								<f:if condition="{model.showElement}">
-									<f:format.raw>{model.layout.elementOuterWrap.0}</f:format.raw>
-										{optgroupOption.label}
-									<f:format.raw>{model.layout.elementOuterWrap.1}</f:format.raw>
+									<f:format.raw>{model.layout.optionOuterWrap.0}</f:format.raw>{optgroupOption.label}<f:format.raw>{model.layout.optionOuterWrap.1}</f:format.raw>
 								</f:if>
 								<f:if condition="{model.additionalArguments.multiple}">
 									<f:then>
@@ -58,9 +56,7 @@
 				<f:else>
 					<f:if condition="{option.selected}">
 						<f:if condition="{model.showElement}">
-							<f:format.raw>{model.layout.elementOuterWrap.0}</f:format.raw>
-								{option.label}
-							<f:format.raw>{model.layout.elementOuterWrap.1}</f:format.raw>
+							<f:format.raw>{model.layout.optionOuterWrap.0}</f:format.raw>{option.label}<f:format.raw>{model.layout.optionOuterWrap.1}</f:format.raw>
 						</f:if>
 						<f:if condition="{model.additionalArguments.multiple}">
 							<f:then>
diff --git a/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/ContainerElements/Checkboxgroup.html b/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/ContainerElements/Checkboxgroup.html
index 022eb930b7c2..132e686b1050 100644
--- a/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/ContainerElements/Checkboxgroup.html
+++ b/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/ContainerElements/Checkboxgroup.html
@@ -1,26 +1,13 @@
 <f:if condition="{model.additionalArguments.atLeastOneCheckedChildElement}">
 	<f:if condition="{model.showElement}">
 		<f:then>
-			<tr class="csc-form-{model.elementCounter} csc-form-element csc-form-element-{model.elementTypeLowerCase}">
-				<td colspan="2">
-					<table cellspacing="0" style="padding-left: 20px; margin-bottom: 20px;">
-						<f:if condition="{model.additionalArguments.legend}">
-							<thead>
-								<tr>
-									<th colspan="2" align="left">
-										{model.additionalArguments.legend}
-									</th>
-								</tr>
-							</thead>
-						</f:if>
-						<tbody>
-							<f:for each="{model.childElements}" as="element">
-								<f:render partial="{element.partialPath}" arguments="{model: element}" />
-							</f:for>
-						</tbody>
-					</table>
-				</td>
-			</tr>
+			<f:format.raw>{model.layout.elementOuterWrap.0}</f:format.raw>
+			<f:format.raw>{model.layout.containerInnerWrap.0}</f:format.raw>
+				<f:for each="{model.childElements}" as="element">
+					<f:render partial="{element.partialPath}" arguments="{model: element}" />
+				</f:for>
+			<f:format.raw>{model.layout.containerInnerWrap.1}</f:format.raw>
+			<f:format.raw>{model.layout.elementOuterWrap.1}</f:format.raw>
 		</f:then>
 		<f:else>
 			<f:for each="{model.childElements}" as="element">
diff --git a/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/ContainerElements/Fieldset.html b/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/ContainerElements/Fieldset.html
index 2e3fbe73801d..b3be1fb73090 100644
--- a/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/ContainerElements/Fieldset.html
+++ b/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/ContainerElements/Fieldset.html
@@ -1,26 +1,13 @@
 <f:if condition="{model.childElements.0}">
 	<f:if condition="{model.showElement}">
 		<f:then>
-			<tr class="csc-form-{model.elementCounter} csc-form-element csc-form-element-{model.elementTypeLowerCase}">
-				<td colspan="2">
-					<table cellspacing="0" style="padding-left: 20px; margin-bottom: 20px;">
-						<f:if condition="{model.additionalArguments.legend}">
-							<thead>
-								<tr>
-									<th colspan="2" align="left">
-										{model.additionalArguments.legend}
-									</th>
-								</tr>
-							</thead>
-						</f:if>
-						<tbody>
-							<f:for each="{model.childElements}" as="element">
-								<f:render partial="{element.partialPath}" arguments="{model: element}" />
-							</f:for>
-						</tbody>
-					</table>
-				</td>
-			</tr>
+			<f:format.raw>{model.layout.elementOuterWrap.0}</f:format.raw>
+			<f:format.raw>{model.layout.containerInnerWrap.0}</f:format.raw>
+				<f:for each="{model.childElements}" as="element">
+					<f:render partial="{element.partialPath}" arguments="{model: element}" />
+				</f:for>
+			<f:format.raw>{model.layout.containerInnerWrap.1}</f:format.raw>
+			<f:format.raw>{model.layout.elementOuterWrap.1}</f:format.raw>
 		</f:then>
 		<f:else>
 			<f:for each="{model.childElements}" as="element">
diff --git a/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/ContainerElements/Form.html b/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/ContainerElements/Form.html
index dc4d724a604f..2113e676d6d3 100644
--- a/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/ContainerElements/Form.html
+++ b/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/ContainerElements/Form.html
@@ -1,14 +1,5 @@
-<html>
-	<head>
-		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-	</head>
-	<body>
-		<table cellspacing="0">
-			<tbody>
-			<f:for each="{model.childElements}" as="element">
-				<f:render partial="{element.partialPath}" arguments="{model: element}" />
-			</f:for>
-			</tbody>
-		</table>
-	</body>
-</html>
\ No newline at end of file
+<f:format.raw>{model.layout.containerInnerWrap.0}</f:format.raw>
+<f:for each="{model.childElements}" as="element">
+	<f:render partial="{element.partialPath}" arguments="{model: element}" />
+</f:for>
+<f:format.raw>{model.layout.containerInnerWrap.1}</f:format.raw>
\ No newline at end of file
diff --git a/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/ContainerElements/Radiogroup.html b/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/ContainerElements/Radiogroup.html
index 022eb930b7c2..132e686b1050 100644
--- a/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/ContainerElements/Radiogroup.html
+++ b/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/ContainerElements/Radiogroup.html
@@ -1,26 +1,13 @@
 <f:if condition="{model.additionalArguments.atLeastOneCheckedChildElement}">
 	<f:if condition="{model.showElement}">
 		<f:then>
-			<tr class="csc-form-{model.elementCounter} csc-form-element csc-form-element-{model.elementTypeLowerCase}">
-				<td colspan="2">
-					<table cellspacing="0" style="padding-left: 20px; margin-bottom: 20px;">
-						<f:if condition="{model.additionalArguments.legend}">
-							<thead>
-								<tr>
-									<th colspan="2" align="left">
-										{model.additionalArguments.legend}
-									</th>
-								</tr>
-							</thead>
-						</f:if>
-						<tbody>
-							<f:for each="{model.childElements}" as="element">
-								<f:render partial="{element.partialPath}" arguments="{model: element}" />
-							</f:for>
-						</tbody>
-					</table>
-				</td>
-			</tr>
+			<f:format.raw>{model.layout.elementOuterWrap.0}</f:format.raw>
+			<f:format.raw>{model.layout.containerInnerWrap.0}</f:format.raw>
+				<f:for each="{model.childElements}" as="element">
+					<f:render partial="{element.partialPath}" arguments="{model: element}" />
+				</f:for>
+			<f:format.raw>{model.layout.containerInnerWrap.1}</f:format.raw>
+			<f:format.raw>{model.layout.elementOuterWrap.1}</f:format.raw>
 		</f:then>
 		<f:else>
 			<f:for each="{model.childElements}" as="element">
diff --git a/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/FlatElements/Checkbox.html b/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/FlatElements/Checkbox.html
index 62ece06af8fa..f9f417aada03 100644
--- a/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/FlatElements/Checkbox.html
+++ b/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/FlatElements/Checkbox.html
@@ -1,9 +1,6 @@
 <f:if condition="{model.showElement}">
-<f:if condition="{model.additionalArguments.checked} == 'checked'">
-<tr class="csc-form-{model.elementCounter} csc-form-element csc-form-element-{model.elementTypeLowerCase}">
-  <td style="width: 200px;">
-    <em>{model.additionalArguments.label}</em>
-  </td>
-</tr>
-</f:if>
-</f:if>
+	<f:if condition="{model.additionalArguments.checked} == 'checked'">
+		<f:format.raw>{model.layout.elementOuterWrap.0}</f:format.raw>
+		<f:format.raw>{model.layout.elementOuterWrap.1}</f:format.raw>
+	</f:if>
+</f:if>
\ No newline at end of file
diff --git a/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/FlatElements/Input.html b/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/FlatElements/Input.html
index a32f76c43dc0..131deb003597 100644
--- a/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/FlatElements/Input.html
+++ b/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/FlatElements/Input.html
@@ -1,8 +1,5 @@
 <f:if condition="{model.showElement}">
-<tr class="csc-form-{model.elementCounter} csc-form-element csc-form-element-{model.elementTypeLowerCase}">
-  <td style="width: 200px;">
-    <em>{model.additionalArguments.label}</em>
-  </td>
-  <td>{model.additionalArguments.value}</td>
-</tr>
+	<f:format.raw>{model.layout.elementOuterWrap.0}</f:format.raw>
+		{model.additionalArguments.value}
+	<f:format.raw>{model.layout.elementOuterWrap.1}</f:format.raw>
 </f:if>
diff --git a/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/FlatElements/Radio.html b/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/FlatElements/Radio.html
index 1df5f74cc34b..f9f417aada03 100644
--- a/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/FlatElements/Radio.html
+++ b/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/FlatElements/Radio.html
@@ -1,9 +1,6 @@
 <f:if condition="{model.showElement}">
-<tr class="csc-form-{model.elementCounter} csc-form-element csc-form-element-{model.elementTypeLowerCase}">
-<f:if condition="{model.additionalArguments.checked} == 'checked'">
-  <td style="width: 200px;">
-    <em>{model.additionalArguments.label}</em>
-  </td>
-</f:if>
-</tr>
+	<f:if condition="{model.additionalArguments.checked} == 'checked'">
+		<f:format.raw>{model.layout.elementOuterWrap.0}</f:format.raw>
+		<f:format.raw>{model.layout.elementOuterWrap.1}</f:format.raw>
+	</f:if>
 </f:if>
\ No newline at end of file
diff --git a/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/FlatElements/Select.html b/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/FlatElements/Select.html
index ffa5c6198b0b..5b25ee980197 100644
--- a/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/FlatElements/Select.html
+++ b/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/FlatElements/Select.html
@@ -1,26 +1,23 @@
 {namespace form=TYPO3\CMS\Form\ViewHelpers}
 <f:if condition="{model.showElement}">
-<tr class="csc-form-{model.elementCounter} csc-form-element csc-form-element-{model.elementTypeLowerCase}">
-  <td style="width: 200px;">
-    <em>{model.additionalArguments.label}</em>
-  </td>
-  <td>
-<f:for each="{form:aggregateSelectOptions(model:model)}" as="option">
-<f:if condition="{option.options}">
-<f:then>
-<f:for each="{option.options}" as="optgroupOption">
-<f:if condition="{optgroupOption.selected}">
-    <div class="csc-form-element csc-form-element-{model.elementTypeLowerCase}">{optgroupOption.label}</div>
-</f:if>
-</f:for>
-</f:then>
-<f:else>
-<f:if condition="{option.selected}">
-    <div class="csc-form-element csc-form-element-{model.elementTypeLowerCase}">{option.label}</div>
-</f:if>
-</f:else>
-</f:if>
-</f:for>
-  </td>
-</tr>
+	<f:format.raw>{model.layout.elementOuterWrap.0}</f:format.raw>
+
+	<f:for each="<form:aggregateSelectOptions model='{model}' />" as="option">
+		<f:if condition="{option.options}">
+			<f:then>
+				<f:for each="{option.options}" as="optgroupOption">
+					<f:if condition="{optgroupOption.selected} == 'selected'">
+						<f:format.raw>{model.layout.optionOuterWrap.0}</f:format.raw>{optgroupOption.label}<f:format.raw>{model.layout.optionOuterWrap.1}</f:format.raw>
+					</f:if>
+				</f:for>
+			</f:then>
+			<f:else>
+				<f:if condition="{option.selected} == 'selected'">
+					<f:format.raw>{model.layout.optionOuterWrap.0}</f:format.raw>{option.label}<f:format.raw>{model.layout.optionOuterWrap.1}</f:format.raw>
+				</f:if>
+			</f:else>
+		</f:if>
+	</f:for>
+
+	<f:format.raw>{model.layout.elementOuterWrap.1}</f:format.raw>
 </f:if>
diff --git a/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/FlatElements/Textarea.html b/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/FlatElements/Textarea.html
index 5ac6424999ee..b18af108cb4c 100644
--- a/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/FlatElements/Textarea.html
+++ b/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/FlatElements/Textarea.html
@@ -1,8 +1,5 @@
 <f:if condition="{model.showElement}">
-<tr class="csc-form-{model.elementCounter} csc-form-element csc-form-element-{model.elementTypeLowerCase}">
-  <td style="width: 200px;" valign="top">
-    <em>{model.additionalArguments.label}</em>
-  </td>
-  <td>{model.additionalArguments.text}</td>
-</tr>
+	<f:format.raw>{model.layout.elementOuterWrap.0}</f:format.raw>
+		{model.additionalArguments.text}
+	<f:format.raw>{model.layout.elementOuterWrap.1}</f:format.raw>
 </f:if>
\ No newline at end of file
diff --git a/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/FlatElements/Textfield.html b/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/FlatElements/Textfield.html
index a32f76c43dc0..131deb003597 100644
--- a/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/FlatElements/Textfield.html
+++ b/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/FlatElements/Textfield.html
@@ -1,8 +1,5 @@
 <f:if condition="{model.showElement}">
-<tr class="csc-form-{model.elementCounter} csc-form-element csc-form-element-{model.elementTypeLowerCase}">
-  <td style="width: 200px;">
-    <em>{model.additionalArguments.label}</em>
-  </td>
-  <td>{model.additionalArguments.value}</td>
-</tr>
+	<f:format.raw>{model.layout.elementOuterWrap.0}</f:format.raw>
+		{model.additionalArguments.value}
+	<f:format.raw>{model.layout.elementOuterWrap.1}</f:format.raw>
 </f:if>
diff --git a/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/FlatElements/Upload.html b/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/FlatElements/Upload.html
index 042c67be9ba0..f9eec9cfaa4c 100644
--- a/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/FlatElements/Upload.html
+++ b/typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/FlatElements/Upload.html
@@ -1,10 +1,5 @@
 <f:if condition="{model.showElement}">
-<tr class="csc-form-{model.elementCounter} csc-form-element csc-form-element-{model.elementTypeLowerCase}">
-  <td style="width: 200px;">
-    <em>{model.additionalArguments.label}</em>
-  </td>
-  <td>
-<f:for each="{model.additionalArguments.uploadedFiles}" as="uploadedFile">{uploadedFile.originalFilename}<br /></f:for>
-  </td>
-</tr>
+	<f:format.raw>{model.layout.elementOuterWrap.0}</f:format.raw>
+		<f:for each="{model.additionalArguments.uploadedFiles}" as="uploadedFile">{uploadedFile.originalFilename}<br /></f:for>
+	<f:format.raw>{model.layout.elementOuterWrap.1}</f:format.raw>
 </f:if>
diff --git a/typo3/sysext/form/Resources/Private/Partials/Compatibility/Show/ContainerElements/Checkboxgroup.html b/typo3/sysext/form/Resources/Private/Partials/Compatibility/Show/ContainerElements/Checkboxgroup.html
index 211281bc0224..1477fb8198c1 100644
--- a/typo3/sysext/form/Resources/Private/Partials/Compatibility/Show/ContainerElements/Checkboxgroup.html
+++ b/typo3/sysext/form/Resources/Private/Partials/Compatibility/Show/ContainerElements/Checkboxgroup.html
@@ -1,22 +1,35 @@
 <f:if condition="{model.showElement}">
 	<f:then>
-		<f:format.raw>{model.layout.elementOuterWrap.0}</f:format.raw>
-			<fieldset
-			<f:for each="{model.htmlAttributes}" as="htmAttributeValue" key="htmAttributeKey">
-				{htmAttributeKey}="{htmAttributeValue}"
-			</f:for>
-			>
-				<f:if condition="{model.additionalArguments.legend}">
-					<legend>{model.additionalArguments.legend}</legend>
-				</f:if>
-
+		<f:if condition="{model.layout.noFieldsetTag}">
+			<f:then>
+				<f:format.raw>{model.layout.elementOuterWrap.0}</f:format.raw>
 				<f:format.raw>{model.layout.containerInnerWrap.0}</f:format.raw>
 					<f:for each="{model.childElements}" as="element">
 						<f:render partial="{themeName}/Show/{element.partialPath}" arguments="{model: element, themeName: themeName}" />
 					</f:for>
 				<f:format.raw>{model.layout.containerInnerWrap.1}</f:format.raw>
-			</fieldset>
-		<f:format.raw>{model.layout.elementOuterWrap.1}</f:format.raw>
+				<f:format.raw>{model.layout.elementOuterWrap.1}</f:format.raw>
+			</f:then>
+			<f:else>
+				<f:format.raw>{model.layout.elementOuterWrap.0}</f:format.raw>
+					<fieldset
+					<f:for each="{model.htmlAttributes}" as="htmAttributeValue" key="htmAttributeKey">
+						{htmAttributeKey}="{htmAttributeValue}"
+					</f:for>
+					>
+						<f:if condition="{model.additionalArguments.legend}">
+							<legend>{model.additionalArguments.legend}</legend>
+						</f:if>
+
+						<f:format.raw>{model.layout.containerInnerWrap.0}</f:format.raw>
+							<f:for each="{model.childElements}" as="element">
+								<f:render partial="{themeName}/Show/{element.partialPath}" arguments="{model: element, themeName: themeName}" />
+							</f:for>
+						<f:format.raw>{model.layout.containerInnerWrap.1}</f:format.raw>
+					</fieldset>
+				<f:format.raw>{model.layout.elementOuterWrap.1}</f:format.raw>
+			</f:else>
+		</f:if>
 	</f:then>
 	<f:else>
 		<f:for each="{model.childElements}" as="element">
diff --git a/typo3/sysext/form/Resources/Private/Partials/Compatibility/Show/ContainerElements/Fieldset.html b/typo3/sysext/form/Resources/Private/Partials/Compatibility/Show/ContainerElements/Fieldset.html
index 3f31b8576f07..967bf8367638 100644
--- a/typo3/sysext/form/Resources/Private/Partials/Compatibility/Show/ContainerElements/Fieldset.html
+++ b/typo3/sysext/form/Resources/Private/Partials/Compatibility/Show/ContainerElements/Fieldset.html
@@ -1,22 +1,35 @@
 <f:if condition="{model.showElement}">
 	<f:then>
-		<f:format.raw>{model.layout.elementOuterWrap.0}</f:format.raw>
-			<fieldset
-			<f:for each="{model.htmlAttributes}" as="htmAttributeValue" key="htmAttributeKey">
-				{htmAttributeKey}="{htmAttributeValue}"
-			</f:for>
-			>
-				<f:if condition="{model.additionalArguments.legend}">
-					<legend>{model.additionalArguments.legend}</legend>
-				</f:if>
-
+		<f:if condition="{model.layout.noFieldsetTag}">
+			<f:then>
+				<f:format.raw>{model.layout.elementOuterWrap.0}</f:format.raw>
 				<f:format.raw>{model.layout.containerInnerWrap.0}</f:format.raw>
 					<f:for each="{model.childElements}" as="element">
 						<f:render partial="{themeName}/Show/{element.partialPath}" arguments="{model: element, themeName: themeName}" />
 					</f:for>
 				<f:format.raw>{model.layout.containerInnerWrap.1}</f:format.raw>
-			</fieldset>
-		<f:format.raw>{model.layout.elementOuterWrap.1}</f:format.raw>
+				<f:format.raw>{model.layout.elementOuterWrap.1}</f:format.raw>
+			</f:then>
+			<f:else>
+				<f:format.raw>{model.layout.elementOuterWrap.0}</f:format.raw>
+					<fieldset
+					<f:for each="{model.htmlAttributes}" as="htmAttributeValue" key="htmAttributeKey">
+						{htmAttributeKey}="{htmAttributeValue}"
+					</f:for>
+					>
+						<f:if condition="{model.additionalArguments.legend}">
+							<legend>{model.additionalArguments.legend}</legend>
+						</f:if>
+
+						<f:format.raw>{model.layout.containerInnerWrap.0}</f:format.raw>
+							<f:for each="{model.childElements}" as="element">
+								<f:render partial="{themeName}/Show/{element.partialPath}" arguments="{model: element, themeName: themeName}" />
+							</f:for>
+						<f:format.raw>{model.layout.containerInnerWrap.1}</f:format.raw>
+					</fieldset>
+				<f:format.raw>{model.layout.elementOuterWrap.1}</f:format.raw>
+			</f:else>
+		</f:if>
 	</f:then>
 	<f:else>
 		<f:for each="{model.childElements}" as="element">
diff --git a/typo3/sysext/form/Resources/Private/Partials/Compatibility/Show/ContainerElements/Radiogroup.html b/typo3/sysext/form/Resources/Private/Partials/Compatibility/Show/ContainerElements/Radiogroup.html
index 211281bc0224..1477fb8198c1 100644
--- a/typo3/sysext/form/Resources/Private/Partials/Compatibility/Show/ContainerElements/Radiogroup.html
+++ b/typo3/sysext/form/Resources/Private/Partials/Compatibility/Show/ContainerElements/Radiogroup.html
@@ -1,22 +1,35 @@
 <f:if condition="{model.showElement}">
 	<f:then>
-		<f:format.raw>{model.layout.elementOuterWrap.0}</f:format.raw>
-			<fieldset
-			<f:for each="{model.htmlAttributes}" as="htmAttributeValue" key="htmAttributeKey">
-				{htmAttributeKey}="{htmAttributeValue}"
-			</f:for>
-			>
-				<f:if condition="{model.additionalArguments.legend}">
-					<legend>{model.additionalArguments.legend}</legend>
-				</f:if>
-
+		<f:if condition="{model.layout.noFieldsetTag}">
+			<f:then>
+				<f:format.raw>{model.layout.elementOuterWrap.0}</f:format.raw>
 				<f:format.raw>{model.layout.containerInnerWrap.0}</f:format.raw>
 					<f:for each="{model.childElements}" as="element">
 						<f:render partial="{themeName}/Show/{element.partialPath}" arguments="{model: element, themeName: themeName}" />
 					</f:for>
 				<f:format.raw>{model.layout.containerInnerWrap.1}</f:format.raw>
-			</fieldset>
-		<f:format.raw>{model.layout.elementOuterWrap.1}</f:format.raw>
+				<f:format.raw>{model.layout.elementOuterWrap.1}</f:format.raw>
+			</f:then>
+			<f:else>
+				<f:format.raw>{model.layout.elementOuterWrap.0}</f:format.raw>
+					<fieldset
+					<f:for each="{model.htmlAttributes}" as="htmAttributeValue" key="htmAttributeKey">
+						{htmAttributeKey}="{htmAttributeValue}"
+					</f:for>
+					>
+						<f:if condition="{model.additionalArguments.legend}">
+							<legend>{model.additionalArguments.legend}</legend>
+						</f:if>
+
+						<f:format.raw>{model.layout.containerInnerWrap.0}</f:format.raw>
+							<f:for each="{model.childElements}" as="element">
+								<f:render partial="{themeName}/Show/{element.partialPath}" arguments="{model: element, themeName: themeName}" />
+							</f:for>
+						<f:format.raw>{model.layout.containerInnerWrap.1}</f:format.raw>
+					</fieldset>
+				<f:format.raw>{model.layout.elementOuterWrap.1}</f:format.raw>
+			</f:else>
+		</f:if>
 	</f:then>
 	<f:else>
 		<f:for each="{model.childElements}" as="element">
-- 
GitLab