[BUGFIX] Two mailforms on a page cause error on field validation 78/22478/2
authorErnesto Baschny <ernst@cron-it.de>
Tue, 27 Nov 2012 01:38:49 +0000 (02:38 +0100)
committerWouter Wolters <typo3@wouterwolters.nl>
Mon, 22 Jul 2013 11:14:15 +0000 (13:14 +0200)
Check formname for uniqueness and if need append a unique hash.

Change-Id: Ifd33c5130c383f3afc3e5e6d80c1be017f25ec5b
Releases: 6.2, 6.1, 6.0, 4.7, 4.5
Fixes: #16114
Reviewed-on: https://review.typo3.org/22478
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
typo3/sysext/frontend/Classes/ContentObject/FormContentObject.php
typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php

index ba1ed71..aaedaab 100644 (file)
@@ -121,12 +121,9 @@ class FormContentObject extends \TYPO3\CMS\Frontend\ContentObject\AbstractConten
                $xhtmlStrict = \TYPO3\CMS\Core\Utility\GeneralUtility::inList('xhtml_strict,xhtml_11,xhtml_2', $GLOBALS['TSFE']->xhtmlDoctype);
                // Formname
                $formName = isset($conf['formName.']) ? $this->cObj->stdWrap($conf['formName'], $conf['formName.']) : $conf['formName'];
-               if ($formName) {
-                       $formName = $this->cObj->cleanFormName($formName);
-               } else {
-                       // form name has to start with a letter to reach XHTML compliance
-                       $formName = 'a' . $GLOBALS['TSFE']->uniqueHash();
-               }
+               $formName = $this->cObj->cleanFormName($formName);
+               $formName = $GLOBALS['TSFE']->getUniqueId($formName);
+
                $fieldPrefix = isset($conf['fieldPrefix.']) ? $this->cObj->stdWrap($conf['fieldPrefix'], $conf['fieldPrefix.']) : $conf['fieldPrefix'];
                if (isset($conf['fieldPrefix']) || isset($conf['fieldPrefix.'])) {
                        if ($fieldPrefix) {
@@ -636,4 +633,4 @@ class FormContentObject extends \TYPO3\CMS\Frontend\ContentObject\AbstractConten
 }
 
 
-?>
\ No newline at end of file
+?>
index 71ce138..f18874a 100644 (file)
@@ -630,6 +630,11 @@ class TypoScriptFrontendController {
        public $anchorPrefix = '';
 
        /**
+        * IDs we already rendered for this page (to make sure they are unique)
+        */
+       private $usedUniqueIds = array();
+
+       /**
         * Page content render object
         *
         * @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
@@ -4600,6 +4605,26 @@ if (version == "n3") {
                \TYPO3\CMS\Core\Utility\GeneralUtility::plainMailEncoded($email, $subject, $message, $headers, $encoding, $charset);
        }
 
+       /**
+        * Returns a unique id to be used as a XML ID (in HTML / XHTML mode)
+        *
+        * @param string $desired The desired id. If already used it is suffixed with a number
+        * @return string The unique id
+        */
+       public function getUniqueId($desired = '') {
+               if ($desired === '') {
+                       // id has to start with a letter to reach XHTML compliance
+                       $uniqueId = 'a' . $this->uniqueHash();
+               } else {
+                       $uniqueId = $desired;
+                       for ($i = 1; isset($this->usedUniqueIds[$uniqueId]); $i++) {
+                               $uniqueId = $desired . '_' . $i;
+                       }
+               }
+               $this->usedUniqueIds[$uniqueId] = TRUE;
+               return $uniqueId;
+       }
+
        /*********************************************
         *
         * Localization and character set conversion