2 namespace TYPO3\CMS\Form\Controller
;
4 /***************************************************************
7 * (c) 2008 Patrick Broens (patrick@patrickbroens.nl)
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
27 * Main controller for Forms. All requests come through this class
28 * and are routed to the model and view layers for processing.
30 * @category Controller
31 * @author Patrick Broens <patrick@patrickbroens.nl>
33 class FormController
{
36 * The TypoScript array
40 protected $typoscript = array();
43 * @var \TYPO3\CMS\Form\Domain\Factory\TypoScriptFactory
45 protected $typoscriptFactory;
48 * @var \TYPO3\CMS\Form\Localization
50 protected $localizationHandler;
53 * @var \TYPO3\CMS\Form\Request
55 protected $requestHandler;
58 * @var \TYPO3\CMS\Form\Utility\ValidatorUtility
65 * @param array $typoscript TS configuration for this cObject
68 public function initialize(array $typoscript) {
69 $this->typoscriptFactory
= \TYPO3\CMS\Core\Utility\GeneralUtility
::makeInstance('TYPO3\\CMS\\Form\\Domain\\Factory\\TypoScriptFactory');
70 $this->localizationHandler
= \TYPO3\CMS\Core\Utility\GeneralUtility
::makeInstance('TYPO3\\CMS\\Form\\Localization');
71 $this->requestHandler
= $this->typoscriptFactory
->setRequestHandler($typoscript);
72 $this->validate
= $this->typoscriptFactory
->setRules($typoscript);
73 $this->typoscript
= $typoscript;
77 * Renders the application defined cObject FORM
78 * which overrides the TYPO3 default cObject FORM
80 * First we make a COA_INT out of it, because it does not need to be cached
81 * Then we send a FORM_INT to the COA_INT
82 * When this is read, it will call the FORM class again.
84 * It simply calls execute because this function name is not really descriptive
85 * but is needed by the core of TYPO3
87 * @param string $typoScriptObjectName Name of the object
88 * @param array $typoScript TS configuration for this cObject
89 * @param string $typoScriptKey A string label used for the internal debugging tracking.
90 * @param \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObject reference
91 * @return string HTML output
93 public function cObjGetSingleExt($typoScriptObjectName, array $typoScript, $typoScriptKey, \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
$contentObject) {
95 if ($typoScriptObjectName === 'FORM') {
96 if ($contentObject->data
['CType'] === 'mailform') {
97 $bodytext = $contentObject->data
['bodytext'];
98 /** @var $typoScriptParser \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser */
99 $typoScriptParser = \TYPO3\CMS\Core\Utility\GeneralUtility
::makeInstance('TYPO3\\CMS\\Core\\TypoScript\\Parser\\TypoScriptParser');
100 $typoScriptParser->parse($bodytext);
101 $mergedTypoScript = \TYPO3\CMS\Core\Utility\GeneralUtility
::array_merge_recursive_overrule((array) $typoScriptParser->setup
, (array) $typoScript);
102 // Disables content elements since TypoScript is handled that could contain insecure settings:
103 $mergedTypoScript[\TYPO3\CMS\Form\Domain\Factory\TypoScriptFactory
::PROPERTY_DisableContentElement
] = TRUE;
105 $newTypoScript = array(
107 '10.' => $mergedTypoScript
109 $content = $contentObject->COBJ_ARRAY($newTypoScript, 'INT');
110 // Only apply stdWrap to TypoScript that was NOT created by the wizard:
111 if (isset($typoScript['stdWrap.'])) {
112 $content = $contentObject->stdWrap($content, $typoScript['stdWrap.']);
114 } elseif ($typoScriptObjectName === 'FORM_INT') {
115 $this->initialize($typoScript);
116 $content = $this->execute();
122 * Build the models and views and renders the output from the views
124 * @return string HTML Output
126 public function execute() {
128 if ($this->showForm()) {
129 $content = $this->renderForm();
130 } elseif ($this->showConfirmation()) {
131 $content = $this->renderConfirmation();
133 $content = $this->doPostProcessing();
139 * Check if the form needs to be displayed
141 * This is TRUE when nothing has been submitted,
142 * when data has been submitted but the validation rules do not fit
143 * or when the user returns from the confirmation screen.
145 * @return boolean TRUE when form needs to be shown
147 protected function showForm() {
149 $submittedByPrefix = $this->requestHandler
->getByMethod();
150 if ($submittedByPrefix === NULL ||
!empty($submittedByPrefix) && !$this->validate
->isValid() ||
!empty($submittedByPrefix) && $this->validate
->isValid() && $this->requestHandler
->getPost('confirmation-false', NULL) !== NULL) {
159 * @return string The form HTML
161 protected function renderForm() {
162 $this->requestHandler
->destroySession();
163 $form = $this->typoscriptFactory
->buildModelFromTyposcript($this->typoscript
);
164 /** @var $view \TYPO3\CMS\Form\View\Form\FormView */
165 $view = \TYPO3\CMS\Core\Utility\GeneralUtility
::makeInstance('TYPO3\\CMS\\Form\\View\\Form\\FormView', $form);
170 * Check if the confirmation message needs to be displayed
172 * This is TRUE when data has been submitted,
173 * the validation rules are valid,
174 * the confirmation screen has been configured in TypoScript
175 * and the confirmation screen has not been submitted
177 * @return boolean TRUE when confirmation screen needs to be shown
179 protected function showConfirmation() {
181 if (isset($this->typoscript
['confirmation']) && $this->typoscript
['confirmation'] == 1 && $this->requestHandler
->getPost('confirmation-true', NULL) === NULL) {
188 * Render the confirmation screen
190 * Stores the submitted data in a session
192 * @return string The confirmation screen HTML
194 protected function renderConfirmation() {
195 $form = $this->typoscriptFactory
->buildModelFromTyposcript($this->typoscript
);
196 $this->requestHandler
->storeSession();
197 $confirmationTyposcript = array();
198 if (isset($this->typoscript
['confirmation.'])) {
199 $confirmationTyposcript = $this->typoscript
['confirmation.'];
201 /** @var $view \TYPO3\CMS\Form\View\Confirmation\ConfirmationView */
202 $view = \TYPO3\CMS\Core\Utility\GeneralUtility
::makeInstance('TYPO3\\CMS\\Form\\View\\Confirmation\\ConfirmationView', $form, $confirmationTyposcript);
207 * Do the post processing
209 * Destroys the session because it is not needed anymore
211 * @return string The post processing HTML
213 protected function doPostProcessing() {
214 $form = $this->typoscriptFactory
->buildModelFromTyposcript($this->typoscript
);
215 $postProcessorTypoScript = array();
216 if (isset($this->typoscript
['postProcessor.'])) {
217 $postProcessorTypoScript = $this->typoscript
['postProcessor.'];
219 /** @var $postProcessor \TYPO3\CMS\Form\PostProcess\PostProcessor */
220 $postProcessor = \TYPO3\CMS\Core\Utility\GeneralUtility
::makeInstance('TYPO3\\CMS\\Form\\PostProcess\\PostProcessor', $form, $postProcessorTypoScript);
221 $content = $postProcessor->process();
222 $this->requestHandler
->destroySession();