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
33 * @author Patrick Broens <patrick@patrickbroens.nl>
35 class FormController
{
38 * The TypoScript array
42 protected $typoscript = array();
45 * @var \TYPO3\CMS\Form\Domain\Factory\TypoScriptFactory
47 protected $typoscriptFactory;
50 * @var \TYPO3\CMS\Form\Localization
52 protected $localizationHandler;
55 * @var \TYPO3\CMS\Form\Request
57 protected $requestHandler;
60 * @var \TYPO3\CMS\Form\Utility\ValidatorUtility
67 * @param array $typoscript TS configuration for this cObject
70 public function initialize(array $typoscript) {
71 $this->typoscriptFactory
= \TYPO3\CMS\Core\Utility\GeneralUtility
::makeInstance('TYPO3\\CMS\\Form\\Domain\\Factory\\TypoScriptFactory');
72 $this->localizationHandler
= \TYPO3\CMS\Core\Utility\GeneralUtility
::makeInstance('TYPO3\\CMS\\Form\\Localization');
73 $this->requestHandler
= $this->typoscriptFactory
->setRequestHandler($typoscript);
74 $this->validate
= $this->typoscriptFactory
->setRules($typoscript);
75 $this->typoscript
= $typoscript;
79 * Renders the application defined cObject FORM
80 * which overrides the TYPO3 default cObject FORM
82 * First we make a COA_INT out of it, because it does not need to be cached
83 * Then we send a FORM_INT to the COA_INT
84 * When this is read, it will call the FORM class again.
86 * It simply calls execute because this function name is not really descriptive
87 * but is needed by the core of TYPO3
89 * @param string $typoScriptObjectName Name of the object
90 * @param array $typoScript TS configuration for this cObject
91 * @param string $typoScriptKey A string label used for the internal debugging tracking.
92 * @param \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObject reference
93 * @return string HTML output
95 public function cObjGetSingleExt($typoScriptObjectName, array $typoScript, $typoScriptKey, \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
$contentObject) {
97 if ($typoScriptObjectName === 'FORM') {
98 if ($contentObject->data
['CType'] === 'mailform') {
99 $bodytext = $contentObject->data
['bodytext'];
100 /** @var $typoScriptParser \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser */
101 $typoScriptParser = \TYPO3\CMS\Core\Utility\GeneralUtility
::makeInstance('TYPO3\\CMS\\Core\\TypoScript\\Parser\\TypoScriptParser');
102 $typoScriptParser->parse($bodytext);
103 $mergedTypoScript = \TYPO3\CMS\Core\Utility\GeneralUtility
::array_merge_recursive_overrule((array) $typoScriptParser->setup
, (array) $typoScript);
104 // Disables content elements since TypoScript is handled that could contain insecure settings:
105 $mergedTypoScript[\TYPO3\CMS\Form\Domain\Factory\TypoScriptFactory
::PROPERTY_DisableContentElement
] = TRUE;
107 $newTypoScript = array(
109 '10.' => $mergedTypoScript
111 $content = $contentObject->COBJ_ARRAY($newTypoScript, 'INT');
112 // Only apply stdWrap to TypoScript that was NOT created by the wizard:
113 if (isset($typoScript['stdWrap.'])) {
114 $content = $contentObject->stdWrap($content, $typoScript['stdWrap.']);
116 } elseif ($typoScriptObjectName === 'FORM_INT') {
117 $this->initialize($typoScript);
118 $content = $this->execute();
124 * Build the models and views and renders the output from the views
126 * @return string HTML Output
128 public function execute() {
130 if ($this->showForm()) {
131 $content = $this->renderForm();
132 } elseif ($this->showConfirmation()) {
133 $content = $this->renderConfirmation();
135 $content = $this->doPostProcessing();
141 * Check if the form needs to be displayed
143 * This is TRUE when nothing has been submitted,
144 * when data has been submitted but the validation rules do not fit
145 * or when the user returns from the confirmation screen.
147 * @return boolean TRUE when form needs to be shown
149 protected function showForm() {
151 $submittedByPrefix = $this->requestHandler
->getByMethod();
152 if ($submittedByPrefix === NULL ||
!empty($submittedByPrefix) && !$this->validate
->isValid() ||
!empty($submittedByPrefix) && $this->validate
->isValid() && $this->requestHandler
->getPost('confirmation-false', NULL) !== NULL) {
161 * @return string The form HTML
163 protected function renderForm() {
164 $this->requestHandler
->destroySession();
165 $form = $this->typoscriptFactory
->buildModelFromTyposcript($this->typoscript
);
166 /** @var $view \TYPO3\CMS\Form\View\Form\FormView */
167 $view = \TYPO3\CMS\Core\Utility\GeneralUtility
::makeInstance('TYPO3\\CMS\\Form\\View\\Form\\FormView', $form);
172 * Check if the confirmation message needs to be displayed
174 * This is TRUE when data has been submitted,
175 * the validation rules are valid,
176 * the confirmation screen has been configured in TypoScript
177 * and the confirmation screen has not been submitted
179 * @return boolean TRUE when confirmation screen needs to be shown
181 protected function showConfirmation() {
183 if (isset($this->typoscript
['confirmation']) && $this->typoscript
['confirmation'] == 1 && $this->requestHandler
->getPost('confirmation-true', NULL) === NULL) {
190 * Render the confirmation screen
192 * Stores the submitted data in a session
194 * @return string The confirmation screen HTML
196 protected function renderConfirmation() {
197 $form = $this->typoscriptFactory
->buildModelFromTyposcript($this->typoscript
);
198 $this->requestHandler
->storeSession();
199 $confirmationTyposcript = array();
200 if (isset($this->typoscript
['confirmation.'])) {
201 $confirmationTyposcript = $this->typoscript
['confirmation.'];
203 /** @var $view \TYPO3\CMS\Form\View\Confirmation\ConfirmationView */
204 $view = \TYPO3\CMS\Core\Utility\GeneralUtility
::makeInstance('TYPO3\\CMS\\Form\\View\\Confirmation\\ConfirmationView', $form, $confirmationTyposcript);
209 * Do the post processing
211 * Destroys the session because it is not needed anymore
213 * @return string The post processing HTML
215 protected function doPostProcessing() {
216 $form = $this->typoscriptFactory
->buildModelFromTyposcript($this->typoscript
);
217 $postProcessorTypoScript = array();
218 if (isset($this->typoscript
['postProcessor.'])) {
219 $postProcessorTypoScript = $this->typoscript
['postProcessor.'];
221 /** @var $postProcessor \TYPO3\CMS\Form\PostProcess\PostProcessor */
222 $postProcessor = \TYPO3\CMS\Core\Utility\GeneralUtility
::makeInstance('TYPO3\\CMS\\Form\\PostProcess\\PostProcessor', $form, $postProcessorTypoScript);
223 $content = $postProcessor->process();
224 $this->requestHandler
->destroySession();