[BUGFIX] add check for empty form values in FORM View
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Classes / View / Confirmation / ConfirmationView.php
1 <?php
2 namespace TYPO3\CMS\Form\View\Confirmation;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2011 Patrick Broens (patrick@patrickbroens.nl)
8 * All rights reserved
9 *
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.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
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.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26 /**
27 * Main view layer for Forms.
28 *
29 * @author Patrick Broens <patrick@patrickbroens.nl>
30 */
31 class ConfirmationView extends \TYPO3\CMS\Form\View\Confirmation\Element\ContainerElementView {
32
33 /**
34 * Default layout of this object
35 *
36 * @var string
37 */
38 protected $layout = '
39 <containerWrap />';
40
41 /**
42 * The TypoScript settings for the confirmation
43 *
44 * @var array
45 */
46 protected $typoscript = array();
47
48 /**
49 * The localization handler
50 *
51 * @var \TYPO3\CMS\Form\Localization
52 */
53 protected $localizationHandler;
54
55 /**
56 * The content object
57 *
58 * @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
59 */
60 protected $localCobj;
61
62 /**
63 * Constructor
64 *
65 * @return void
66 */
67 public function __construct(\TYPO3\CMS\Form\Domain\Model\Form $model, array $typoscript) {
68 $this->localCobj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
69 $this->localizationHandler = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\Localization');
70 $this->typoscript = $typoscript;
71 parent::__construct($model);
72 }
73
74 /**
75 * Set the data for the FORM tag
76 *
77 * @param \TYPO3\CMS\Form\Domain\Model\Form $formModel The model of the form
78 * @return void
79 */
80 public function setData(\TYPO3\CMS\Form\Domain\Model\Form $model) {
81 $this->model = (object) $model;
82 }
83
84 /**
85 * Start the main DOMdocument for the form
86 * Return it as a string using saveXML() to get a proper formatted output
87 * (when using formatOutput :-)
88 *
89 * @return string XHTML string containing the whole form
90 */
91 public function get() {
92 $message = $this->getMessage();
93 $node = $this->render('element', FALSE);
94 if ($node !== NULL) {
95 $formInput = LF . html_entity_decode($node->saveXML($node->firstChild), ENT_QUOTES, 'UTF-8') . LF;
96 } else {
97 $formInput = '';
98 }
99 $confirmationButtons = $this->getConfirmationButtons();
100 $content = $message . LF . $formInput . LF . $confirmationButtons;
101 return $content;
102 }
103
104 /**
105 * Construct the message
106 *
107 * The message is a cObj, which can be overriden using the typoscript
108 * setting confirmation.message, like
109 *
110 * confirmation.message = TEXT
111 * confirmation.message.value = Here some text
112 * confirmation.message.wrap = <p>|</p>
113 *
114 * @return string XHTML string containing the message
115 */
116 protected function getMessage() {
117 if (isset($this->typoscript['message']) && isset($this->typoscript['message.'])) {
118 $value = $this->typoscript['message.'];
119 $type = $this->typoscript['message'];
120 } elseif (isset($this->typoscript['message.'])) {
121 $value = $this->typoscript['message.'];
122 $type = 'TEXT';
123 } else {
124 $value['wrap'] = '<p>|</p>';
125 $value['value'] = $this->localizationHandler->getLocalLanguageLabel('tx_form_view_confirmation.message');
126 $type = 'TEXT';
127 }
128 return $this->localCobj->cObjGetSingle($type, $value);
129 }
130
131 protected function getConfirmationButtons() {
132 $requestHandler = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\Request');
133 $prefix = $requestHandler->getPrefix();
134 $action = $this->localCobj->getTypoLink_URL($GLOBALS['TSFE']->id);
135 $confirmationButtons = '
136 <form class="csc-form-confirmation" method="post" action="' . $action . '">
137 <fieldset>
138 <ol>
139 <li class="csc-form-confirmation-false">
140 <input type="submit" value="' . $this->localizationHandler->getLocalLanguageLabel('tx_form_view_confirmation.donotconfirm') . '" name="' . $prefix . '[confirmation-false]" />
141 </li>
142 <li class="csc-form-confirmation-true">
143 <input type="submit" value="' . $this->localizationHandler->getLocalLanguageLabel('tx_form_view_confirmation.confirm') . '" name="' . $prefix . '[confirmation-true]" />
144 </li>
145 </ol>
146 </fieldset>
147 </form>
148 ';
149 return $confirmationButtons;
150 }
151
152 }
153
154
155 ?>