[TASK] Use arrays in str_replace() calls
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Classes / ContentObject / FormContentObject.php
1 <?php
2 namespace TYPO3\CMS\Frontend\ContentObject;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2010-2013 Xavier Perseguers <typo3@perseguers.ch>
8 * (c) 2010-2013 Steffen Kamper <steffen@typo3.org>
9 * All rights reserved
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 * A copy is found in the textfile GPL.txt and important notices to the license
20 * from the author is found in LICENSE.txt distributed with these scripts.
21 *
22 *
23 * This script is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * This copyright notice MUST APPEAR in all copies of the script!
29 ***************************************************************/
30
31 use TYPO3\CMS\Core\Utility\GeneralUtility;
32
33 /**
34 * Contains FORM class object.
35 *
36 * @author Xavier Perseguers <typo3@perseguers.ch>
37 * @author Steffen Kamper <steffen@typo3.org>
38 */
39 class FormContentObject extends \TYPO3\CMS\Frontend\ContentObject\AbstractContentObject {
40
41 /**
42 * Rendering the cObject, FORM
43 *
44 * Note on $formData:
45 * In the optional $formData array each entry represents a line in the ordinary setup.
46 * In those entries each entry (0,1,2...) represents a space normally divided by the '|' line.
47 *
48 * $formData [] = array('Name:', 'name=input, 25 ', 'Default value....');
49 * $formData [] = array('Email:', 'email=input, 25 ', 'Default value for email....');
50 *
51 * - corresponds to the $conf['data'] value being :
52 * Name:|name=input, 25 |Default value....||Email:|email=input, 25 |Default value for email....
53 *
54 * If $formData is an array the value of $conf['data'] is ignored.
55 *
56 * @param array $conf Array of TypoScript properties
57 * @param array $formData Alternative formdata overriding whatever comes from TypoScript
58 * @return string Output
59 */
60 public function render($conf = array(), $formData = '') {
61 $content = '';
62 if (is_array($formData)) {
63 $dataArray = $formData;
64 } else {
65 $data = isset($conf['data.']) ? $this->cObj->stdWrap($conf['data'], $conf['data.']) : $conf['data'];
66 // Clearing dataArr
67 $dataArray = array();
68 // Getting the original config
69 if (trim($data)) {
70 $data = str_replace(LF, '||', $data);
71 $dataArray = explode('||', $data);
72 }
73 // Adding the new dataArray config form:
74 if (is_array($conf['dataArray.'])) {
75 // dataArray is supplied
76 $sortedKeyArray = \TYPO3\CMS\Core\TypoScript\TemplateService::sortedKeyList($conf['dataArray.'], TRUE);
77 foreach ($sortedKeyArray as $theKey) {
78 $singleKeyArray = $conf['dataArray.'][$theKey . '.'];
79 if (is_array($singleKeyArray)) {
80 $temp = array();
81 $label = isset($singleKeyArray['label.']) ? $this->cObj->stdWrap($singleKeyArray['label'], $singleKeyArray['label.']) : $singleKeyArray['label'];
82 list($temp[0]) = explode('|', $label);
83 $type = isset($singleKeyArray['type.']) ? $this->cObj->stdWrap($singleKeyArray['type'], $singleKeyArray['type.']) : $singleKeyArray['type'];
84 list($temp[1]) = explode('|', $type);
85 $required = isset($singleKeyArray['required.']) ? $this->cObj->stdWrap($singleKeyArray['required'], $singleKeyArray['required.']) : $singleKeyArray['required'];
86 if ($required) {
87 $temp[1] = '*' . $temp[1];
88 }
89 $singleValue = isset($singleKeyArray['value.']) ? $this->cObj->stdWrap($singleKeyArray['value'], $singleKeyArray['value.']) : $singleKeyArray['value'];
90 list($temp[2]) = explode('|', $singleValue);
91 // If value array is set, then implode those values.
92 if (is_array($singleKeyArray['valueArray.'])) {
93 $temp_accumulated = array();
94 foreach ($singleKeyArray['valueArray.'] as $singleKey => $singleKey_valueArray) {
95 if (is_array($singleKey_valueArray) && !strcmp((intval($singleKey) . '.'), $singleKey)) {
96 $temp_valueArray = array();
97 $valueArrayLabel = isset($singleKey_valueArray['label.']) ? $this->cObj->stdWrap($singleKey_valueArray['label'], $singleKey_valueArray['label.']) : $singleKey_valueArray['label'];
98 list($temp_valueArray[0]) = explode('=', $valueArrayLabel);
99 $selected = isset($singleKey_valueArray['selected.']) ? $this->cObj->stdWrap($singleKey_valueArray['selected'], $singleKey_valueArray['selected.']) : $singleKey_valueArray['selected'];
100 if ($selected) {
101 $temp_valueArray[0] = '*' . $temp_valueArray[0];
102 }
103 $singleKeyValue = isset($singleKey_valueArray['value.']) ? $this->cObj->stdWrap($singleKey_valueArray['value'], $singleKey_valueArray['value.']) : $singleKey_valueArray['value'];
104 list($temp_valueArray[1]) = explode(',', $singleKeyValue);
105 }
106 $temp_accumulated[] = implode('=', $temp_valueArray);
107 }
108 $temp[2] = implode(',', $temp_accumulated);
109 }
110 $specialEval = isset($singleKeyArray['specialEval.']) ? $this->cObj->stdWrap($singleKeyArray['specialEval'], $singleKeyArray['specialEval.']) : $singleKeyArray['specialEval'];
111 list($temp[3]) = explode('|', $specialEval);
112 // Adding the form entry to the dataArray
113 $dataArray[] = implode('|', $temp);
114 }
115 }
116 }
117 }
118 $attachmentCounter = '';
119 $hiddenfields = '';
120 $fieldlist = array();
121 $propertyOverride = array();
122 $fieldname_hashArray = array();
123 $counter = 0;
124 $xhtmlStrict = GeneralUtility::inList('xhtml_strict,xhtml_11,xhtml_2', $GLOBALS['TSFE']->xhtmlDoctype);
125 // Formname
126 $formName = isset($conf['formName.']) ? $this->cObj->stdWrap($conf['formName'], $conf['formName.']) : $conf['formName'];
127 $formName = $this->cObj->cleanFormName($formName);
128 $formName = $GLOBALS['TSFE']->getUniqueId($formName);
129
130 $fieldPrefix = isset($conf['fieldPrefix.']) ? $this->cObj->stdWrap($conf['fieldPrefix'], $conf['fieldPrefix.']) : $conf['fieldPrefix'];
131 if (isset($conf['fieldPrefix']) || isset($conf['fieldPrefix.'])) {
132 if ($fieldPrefix) {
133 $prefix = $this->cObj->cleanFormName($fieldPrefix);
134 } else {
135 $prefix = '';
136 }
137 } else {
138 $prefix = $formName;
139 }
140 foreach ($dataArray as $dataValue) {
141 $counter++;
142 $confData = array();
143 if (is_array($formData)) {
144 $parts = $dataValue;
145 // TRUE...
146 $dataValue = 1;
147 } else {
148 $dataValue = trim($dataValue);
149 $parts = explode('|', $dataValue);
150 }
151 if ($dataValue && strcspn($dataValue, '#/')) {
152 // label:
153 $confData['label'] = GeneralUtility::removeXSS(trim($parts[0]));
154 // field:
155 $fParts = explode(',', $parts[1]);
156 $fParts[0] = trim($fParts[0]);
157 if (substr($fParts[0], 0, 1) == '*') {
158 $confData['required'] = 1;
159 $fParts[0] = substr($fParts[0], 1);
160 }
161 $typeParts = explode('=', $fParts[0]);
162 $confData['type'] = trim(strtolower(end($typeParts)));
163 if (count($typeParts) == 1) {
164 $confData['fieldname'] = $this->cObj->cleanFormName($parts[0]);
165 if (strtolower(preg_replace('/[^[:alnum:]]/', '', $confData['fieldname'])) == 'email') {
166 $confData['fieldname'] = 'email';
167 }
168 // Duplicate fieldnames resolved
169 if (isset($fieldname_hashArray[md5($confData['fieldname'])])) {
170 $confData['fieldname'] .= '_' . $counter;
171 }
172 $fieldname_hashArray[md5($confData['fieldname'])] = $confData['fieldname'];
173 // Attachment names...
174 if ($confData['type'] == 'file') {
175 $confData['fieldname'] = 'attachment' . $attachmentCounter;
176 $attachmentCounter = intval($attachmentCounter) + 1;
177 }
178 } else {
179 $confData['fieldname'] = str_replace(' ', '_', trim($typeParts[0]));
180 }
181 $confData['fieldname'] = htmlspecialchars($confData['fieldname']);
182 $fieldCode = '';
183 $wrapFieldName = isset($conf['wrapFieldName']) ? $this->cObj->stdWrap($conf['wrapFieldName'], $conf['wrapFieldName.']) : $conf['wrapFieldName'];
184 if ($wrapFieldName) {
185 $confData['fieldname'] = $this->cObj->wrap($confData['fieldname'], $wrapFieldName);
186 }
187 // Set field name as current:
188 $this->cObj->setCurrentVal($confData['fieldname']);
189 // Additional parameters
190 if (trim($confData['type'])) {
191 if (isset($conf['params.'][$confData['type']])) {
192 $addParams = isset($conf['params.'][$confData['type'] . '.']) ? trim($this->cObj->stdWrap($conf['params.'][$confData['type']], $conf['params.'][$confData['type'] . '.'])) : trim($conf['params.'][$confData['type']]);
193 } else {
194 $addParams = isset($conf['params.']) ? trim($this->cObj->stdWrap($conf['params'], $conf['params.'])) : trim($conf['params']);
195 }
196 if (strcmp('', $addParams)) {
197 $addParams = ' ' . $addParams;
198 }
199 } else {
200 $addParams = '';
201 }
202 $dontMd5FieldNames = isset($conf['dontMd5FieldNames.']) ? $this->cObj->stdWrap($conf['dontMd5FieldNames'], $conf['dontMd5FieldNames.']) : $conf['dontMd5FieldNames'];
203 if ($dontMd5FieldNames) {
204 $fName = $confData['fieldname'];
205 } else {
206 $fName = md5($confData['fieldname']);
207 }
208 // Accessibility: Set id = fieldname attribute:
209 $accessibility = isset($conf['accessibility.']) ? $this->cObj->stdWrap($conf['accessibility'], $conf['accessibility.']) : $conf['accessibility'];
210 if ($accessibility || $xhtmlStrict) {
211 $elementIdAttribute = ' id="' . $prefix . $fName . '"';
212 } else {
213 $elementIdAttribute = '';
214 }
215 // Create form field based on configuration/type:
216 switch ($confData['type']) {
217 case 'textarea':
218 $cols = trim($fParts[1]) ? intval($fParts[1]) : 20;
219 $compensateFieldWidth = isset($conf['compensateFieldWidth.']) ? $this->cObj->stdWrap($conf['compensateFieldWidth'], $conf['compensateFieldWidth.']) : $conf['compensateFieldWidth'];
220 $compWidth = doubleval($compensateFieldWidth ? $compensateFieldWidth : $GLOBALS['TSFE']->compensateFieldWidth);
221 $compWidth = $compWidth ? $compWidth : 1;
222 $cols = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($cols * $compWidth, 1, 120);
223 $rows = trim($fParts[2]) ? \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($fParts[2], 1, 30) : 5;
224 $wrap = trim($fParts[3]);
225 $noWrapAttr = isset($conf['noWrapAttr.']) ? $this->cObj->stdWrap($conf['noWrapAttr'], $conf['noWrapAttr.']) : $conf['noWrapAttr'];
226 if ($noWrapAttr || $wrap === 'disabled') {
227 $wrap = '';
228 } else {
229 $wrap = $wrap ? ' wrap="' . $wrap . '"' : ' wrap="virtual"';
230 }
231 $noValueInsert = isset($conf['noValueInsert.']) ? $this->cObj->stdWrap($conf['noValueInsert'], $conf['noValueInsert.']) : $conf['noValueInsert'];
232 $default = $this->cObj->getFieldDefaultValue($noValueInsert, $confData['fieldname'], str_replace('\\n', LF, trim($parts[2])));
233 $fieldCode = sprintf('<textarea name="%s"%s cols="%s" rows="%s"%s%s>%s</textarea>', $confData['fieldname'], $elementIdAttribute, $cols, $rows, $wrap, $addParams, GeneralUtility::formatForTextarea($default));
234 break;
235 case 'input':
236
237 case 'password':
238 $size = trim($fParts[1]) ? intval($fParts[1]) : 20;
239 $compensateFieldWidth = isset($conf['compensateFieldWidth.']) ? $this->cObj->stdWrap($conf['compensateFieldWidth'], $conf['compensateFieldWidth.']) : $conf['compensateFieldWidth'];
240 $compWidth = doubleval($compensateFieldWidth ? $compensateFieldWidth : $GLOBALS['TSFE']->compensateFieldWidth);
241 $compWidth = $compWidth ? $compWidth : 1;
242 $size = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($size * $compWidth, 1, 120);
243 $noValueInsert = isset($conf['noValueInsert.']) ? $this->cObj->stdWrap($conf['noValueInsert'], $conf['noValueInsert.']) : $conf['noValueInsert'];
244 $default = $this->cObj->getFieldDefaultValue($noValueInsert, $confData['fieldname'], trim($parts[2]));
245 if ($confData['type'] == 'password') {
246 $default = '';
247 }
248 $max = trim($fParts[2]) ? ' maxlength="' . \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($fParts[2], 1, 1000) . '"' : '';
249 $theType = $confData['type'] == 'input' ? 'text' : 'password';
250 $fieldCode = sprintf('<input type="%s" name="%s"%s size="%s"%s value="%s"%s />', $theType, $confData['fieldname'], $elementIdAttribute, $size, $max, htmlspecialchars($default), $addParams);
251 break;
252 case 'file':
253 $size = trim($fParts[1]) ? \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($fParts[1], 1, 60) : 20;
254 $fieldCode = sprintf('<input type="file" name="%s"%s size="%s"%s />', $confData['fieldname'], $elementIdAttribute, $size, $addParams);
255 break;
256 case 'check':
257 // alternative default value:
258 $noValueInsert = isset($conf['noValueInsert.']) ? $this->cObj->stdWrap($conf['noValueInsert'], $conf['noValueInsert.']) : $conf['noValueInsert'];
259 $default = $this->cObj->getFieldDefaultValue($noValueInsert, $confData['fieldname'], trim($parts[2]));
260 $checked = $default ? ' checked="checked"' : '';
261 $fieldCode = sprintf('<input type="checkbox" value="%s" name="%s"%s%s%s />', 1, $confData['fieldname'], $elementIdAttribute, $checked, $addParams);
262 break;
263 case 'select':
264 $option = '';
265 $valueParts = explode(',', $parts[2]);
266 // size
267 if (strtolower(trim($fParts[1])) == 'auto') {
268 $fParts[1] = count($valueParts);
269 }
270 // Auto size set here. Max 20
271 $size = trim($fParts[1]) ? \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($fParts[1], 1, 20) : 1;
272 // multiple
273 $multiple = strtolower(trim($fParts[2])) == 'm' ? ' multiple="multiple"' : '';
274 // Where the items will be
275 $items = array();
276 //RTF
277 $defaults = array();
278 $pCount = count($valueParts);
279 for ($a = 0; $a < $pCount; $a++) {
280 $valueParts[$a] = trim($valueParts[$a]);
281 // Finding default value
282 if (substr($valueParts[$a], 0, 1) == '*') {
283 $sel = 'selected';
284 $valueParts[$a] = substr($valueParts[$a], 1);
285 } else {
286 $sel = '';
287 }
288 // Get value/label
289 $subParts = explode('=', $valueParts[$a]);
290 // Sets the value
291 $subParts[1] = isset($subParts[1]) ? trim($subParts[1]) : trim($subParts[0]);
292 // Adds the value/label pair to the items-array
293 $items[] = $subParts;
294 if ($sel) {
295 $defaults[] = $subParts[1];
296 }
297 }
298 // alternative default value:
299 $noValueInsert = isset($conf['noValueInsert.']) ? $this->cObj->stdWrap($conf['noValueInsert'], $conf['noValueInsert.']) : $conf['noValueInsert'];
300 $default = $this->cObj->getFieldDefaultValue($noValueInsert, $confData['fieldname'], $defaults);
301 if (!is_array($default)) {
302 $defaults = array();
303 $defaults[] = $default;
304 } else {
305 $defaults = $default;
306 }
307 // Create the select-box:
308 $iCount = count($items);
309 for ($a = 0; $a < $iCount; $a++) {
310 $option .= '<option value="' . $items[$a][1] . '"' . (in_array($items[$a][1], $defaults) ? ' selected="selected"' : '') . '>' . trim($items[$a][0]) . '</option>';
311 }
312 if ($multiple) {
313 // The fieldname must be prepended '[]' if multiple select. And the reason why it's prepended is, because the required-field list later must also have [] prepended.
314 $confData['fieldname'] .= '[]';
315 }
316 $fieldCode = sprintf('<select name="%s"%s size="%s"%s%s>%s</select>', $confData['fieldname'], $elementIdAttribute, $size, $multiple, $addParams, $option);
317 //RTF
318 break;
319 case 'radio':
320 $option = '';
321 $valueParts = explode(',', $parts[2]);
322 // Where the items will be
323 $items = array();
324 $default = '';
325 $pCount = count($valueParts);
326 for ($a = 0; $a < $pCount; $a++) {
327 $valueParts[$a] = trim($valueParts[$a]);
328 if (substr($valueParts[$a], 0, 1) == '*') {
329 $sel = 'checked';
330 $valueParts[$a] = substr($valueParts[$a], 1);
331 } else {
332 $sel = '';
333 }
334 // Get value/label
335 $subParts = explode('=', $valueParts[$a]);
336 // Sets the value
337 $subParts[1] = isset($subParts[1]) ? trim($subParts[1]) : trim($subParts[0]);
338 // Adds the value/label pair to the items-array
339 $items[] = $subParts;
340 if ($sel) {
341 $default = $subParts[1];
342 }
343 }
344 // alternative default value:
345 $noValueInsert = isset($conf['noValueInsert.']) ? $this->cObj->stdWrap($conf['noValueInsert'], $conf['noValueInsert.']) : $conf['noValueInsert'];
346 $default = $this->cObj->getFieldDefaultValue($noValueInsert, $confData['fieldname'], $default);
347 // Create the select-box:
348 $iCount = count($items);
349 for ($a = 0; $a < $iCount; $a++) {
350 $optionParts = '';
351 $radioId = $prefix . $fName . $this->cObj->cleanFormName($items[$a][0]);
352 if ($accessibility) {
353 $radioLabelIdAttribute = ' id="' . $radioId . '"';
354 } else {
355 $radioLabelIdAttribute = '';
356 }
357 $optionParts .= '<input type="radio" name="' . $confData['fieldname'] . '"' . $radioLabelIdAttribute . ' value="' . $items[$a][1] . '"' . (!strcmp($items[$a][1], $default) ? ' checked="checked"' : '') . $addParams . ' />';
358 if ($accessibility) {
359 $label = isset($conf['radioWrap.']) ? $this->cObj->stdWrap(trim($items[$a][0]), $conf['radioWrap.']) : trim($items[$a][0]);
360 $optionParts .= '<label for="' . $radioId . '">' . $label . '</label>';
361 } else {
362 $optionParts .= isset($conf['radioWrap.']) ? $this->cObj->stdWrap(trim($items[$a][0]), $conf['radioWrap.']) : trim($items[$a][0]);
363 }
364 $option .= isset($conf['radioInputWrap.']) ? $this->cObj->stdWrap($optionParts, $conf['radioInputWrap.']) : $optionParts;
365 }
366 if ($accessibility) {
367 $accessibilityWrap = isset($conf['radioWrap.']['accessibilityWrap.']) ? $this->cObj->stdWrap($conf['radioWrap.']['accessibilityWrap'], $conf['radioWrap.']['accessibilityWrap.']) : $conf['radioWrap.']['accessibilityWrap'];
368 if ($accessibilityWrap) {
369 $search = array(
370 '###RADIO_FIELD_ID###',
371 '###RADIO_GROUP_LABEL###'
372 );
373 $replace = array(
374 $elementIdAttribute,
375 $confData['label']
376 );
377 $accessibilityWrap = str_replace($search, $replace, $accessibilityWrap);
378 $option = $this->cObj->wrap($option, $accessibilityWrap);
379 }
380 }
381 $fieldCode = $option;
382 break;
383 case 'hidden':
384 $value = trim($parts[2]);
385 // If this form includes an auto responder message, include a HMAC checksum field
386 // in order to verify potential abuse of this feature.
387 if (strlen($value) && GeneralUtility::inList($confData['fieldname'], 'auto_respond_msg')) {
388 $hmacChecksum = GeneralUtility::hmac($value, 'content_form');
389 $hiddenfields .= sprintf('<input type="hidden" name="auto_respond_checksum" id="%sauto_respond_checksum" value="%s" />', $prefix, $hmacChecksum);
390 }
391 if (strlen($value) && GeneralUtility::inList('recipient_copy,recipient', $confData['fieldname']) && $GLOBALS['TYPO3_CONF_VARS']['FE']['secureFormmail']) {
392 break;
393 }
394 if (strlen($value) && GeneralUtility::inList('recipient_copy,recipient', $confData['fieldname'])) {
395 $value = $GLOBALS['TSFE']->codeString($value);
396 }
397 $hiddenfields .= sprintf('<input type="hidden" name="%s"%s value="%s" />', $confData['fieldname'], $elementIdAttribute, htmlspecialchars($value));
398 break;
399 case 'property':
400 if (GeneralUtility::inList('type,locationData,goodMess,badMess,emailMess', $confData['fieldname'])) {
401 $value = trim($parts[2]);
402 $propertyOverride[$confData['fieldname']] = $value;
403 $conf[$confData['fieldname']] = $value;
404 }
405 break;
406 case 'submit':
407 $value = trim($parts[2]);
408 if ($conf['image.']) {
409 $this->cObj->data[$this->cObj->currentValKey] = $value;
410 $image = $this->cObj->IMG_RESOURCE($conf['image.']);
411 $params = $conf['image.']['params'] ? ' ' . $conf['image.']['params'] : '';
412 $params .= $this->cObj->getAltParam($conf['image.'], FALSE);
413 $params .= $addParams;
414 } else {
415 $image = '';
416 }
417 if ($image) {
418 $fieldCode = sprintf('<input type="image" name="%s"%s src="%s"%s />', $confData['fieldname'], $elementIdAttribute, $image, $params);
419 } else {
420 $fieldCode = sprintf('<input type="submit" name="%s"%s value="%s"%s />', $confData['fieldname'], $elementIdAttribute, GeneralUtility::deHSCentities(htmlspecialchars($value)), $addParams);
421 }
422 break;
423 case 'reset':
424 $value = trim($parts[2]);
425 $fieldCode = sprintf('<input type="reset" name="%s"%s value="%s"%s />', $confData['fieldname'], $elementIdAttribute, GeneralUtility::deHSCentities(htmlspecialchars($value)), $addParams);
426 break;
427 case 'label':
428 $fieldCode = nl2br(htmlspecialchars(trim($parts[2])));
429 break;
430 default:
431 $confData['type'] = 'comment';
432 $fieldCode = trim($parts[2]) . '&nbsp;';
433 }
434 if ($fieldCode) {
435 // Checking for special evaluation modes:
436 if (GeneralUtility::inList('textarea,input,password', $confData['type']) && strlen(trim($parts[3]))) {
437 $modeParameters = GeneralUtility::trimExplode(':', $parts[3]);
438 } else {
439 $modeParameters = array();
440 }
441 // Adding evaluation based on settings:
442 switch ((string) $modeParameters[0]) {
443 case 'EREG':
444 $fieldlist[] = '_EREG';
445 $fieldlist[] = $modeParameters[1];
446 $fieldlist[] = $modeParameters[2];
447 $fieldlist[] = $confData['fieldname'];
448 $fieldlist[] = $confData['label'];
449 // Setting this so "required" layout is used.
450 $confData['required'] = 1;
451 break;
452 case 'EMAIL':
453 $fieldlist[] = '_EMAIL';
454 $fieldlist[] = $confData['fieldname'];
455 $fieldlist[] = $confData['label'];
456 // Setting this so "required" layout is used.
457 $confData['required'] = 1;
458 break;
459 default:
460 if ($confData['required']) {
461 $fieldlist[] = $confData['fieldname'];
462 $fieldlist[] = $confData['label'];
463 }
464 }
465 // Field:
466 $fieldLabel = $confData['label'];
467 if ($accessibility && trim($fieldLabel) && !preg_match('/^(label|hidden|comment)$/', $confData['type'])) {
468 $fieldLabel = '<label for="' . $prefix . $fName . '">' . $fieldLabel . '</label>';
469 }
470 // Getting template code:
471 if (isset($conf['fieldWrap.'])) {
472 $fieldCode = $this->cObj->stdWrap($fieldCode, $conf['fieldWrap.']);
473 }
474 $labelCode = isset($conf['labelWrap.']) ? $this->cObj->stdWrap($fieldLabel, $conf['labelWrap.']) : $fieldLabel;
475 $commentCode = isset($conf['commentWrap.']) ? $this->cObj->stdWrap($confData['label'], $conf['commentWrap.']) : $confData['label'];
476 $result = $conf['layout'];
477 $req = isset($conf['REQ.']) ? $this->cObj->stdWrap($conf['REQ'], $conf['REQ.']) : $conf['REQ'];
478 if ($req && $confData['required']) {
479 if (isset($conf['REQ.']['fieldWrap.'])) {
480 $fieldCode = $this->cObj->stdWrap($fieldCode, $conf['REQ.']['fieldWrap.']);
481 }
482 if (isset($conf['REQ.']['labelWrap.'])) {
483 $labelCode = $this->cObj->stdWrap($fieldLabel, $conf['REQ.']['labelWrap.']);
484 }
485 $reqLayout = isset($conf['REQ.']['layout.']) ? $this->cObj->stdWrap($conf['REQ.']['layout'], $conf['REQ.']['layout.']) : $conf['REQ.']['layout'];
486 if ($reqLayout) {
487 $result = $reqLayout;
488 }
489 }
490 if ($confData['type'] == 'comment') {
491 $commentLayout = isset($conf['COMMENT.']['layout.']) ? $this->cObj->stdWrap($conf['COMMENT.']['layout'], $conf['COMMENT.']['layout.']) : $conf['COMMENT.']['layout'];
492 if ($commentLayout) {
493 $result = $commentLayout;
494 }
495 }
496 if ($confData['type'] == 'check') {
497 $checkLayout = isset($conf['CHECK.']['layout.']) ? $this->cObj->stdWrap($conf['CHECK.']['layout'], $conf['CHECK.']['layout.']) : $conf['CHECK.']['layout'];
498 if ($checkLayout) {
499 $result = $checkLayout;
500 }
501 }
502 if ($confData['type'] == 'radio') {
503 $radioLayout = isset($conf['RADIO.']['layout.']) ? $this->cObj->stdWrap($conf['RADIO.']['layout'], $conf['RADIO.']['layout.']) : $conf['RADIO.']['layout'];
504 if ($radioLayout) {
505 $result = $radioLayout;
506 }
507 }
508 if ($confData['type'] == 'label') {
509 $labelLayout = isset($conf['LABEL.']['layout.']) ? $this->cObj->stdWrap($conf['LABEL.']['layout'], $conf['LABEL.']['layout.']) : $conf['LABEL.']['layout'];
510 if ($labelLayout) {
511 $result = $labelLayout;
512 }
513 }
514 //RTF
515 $content .= str_replace(
516 array(
517 '###FIELD###',
518 '###LABEL###',
519 '###COMMENT###'
520 ),
521 array(
522 $fieldCode,
523 $labelCode,
524 $commentCode
525 ),
526 $result
527 );
528 }
529 }
530 }
531 if (isset($conf['stdWrap.'])) {
532 $content = $this->cObj->stdWrap($content, $conf['stdWrap.']);
533 }
534 // Redirect (external: where to go afterwards. internal: where to submit to)
535 $theRedirect = isset($conf['redirect.']) ? $this->cObj->stdWrap($conf['redirect'], $conf['redirect.']) : $conf['redirect'];
536 // redirect should be set to the page to redirect to after an external script has been used. If internal scripts is used, and if no 'type' is set that dictates otherwise, redirect is used as the url to jump to as long as it's an integer (page)
537 $target = isset($conf['target.']) ? $this->cObj->stdWrap($conf['target'], $conf['target.']) : $conf['target'];
538 // redirect should be set to the page to redirect to after an external script has been used. If internal scripts is used, and if no 'type' is set that dictates otherwise, redirect is used as the url to jump to as long as it's an integer (page)
539 $noCache = isset($conf['no_cache.']) ? $this->cObj->stdWrap($conf['no_cache'], $conf['no_cache.']) : $conf['no_cache'];
540 // redirect should be set to the page to redirect to after an external script has been used. If internal scripts is used, and if no 'type' is set that dictates otherwise, redirect is used as the url to jump to as long as it's an integer (page)
541 $page = $GLOBALS['TSFE']->page;
542 // Internal: Just submit to current page
543 if (!$theRedirect) {
544 $LD = $GLOBALS['TSFE']->tmpl->linkData($page, $target, $noCache, 'index.php', '', $this->cObj->getClosestMPvalueForPage($page['uid']));
545 } elseif (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($theRedirect)) {
546 // Internal: Submit to page with ID $theRedirect
547 $page = $GLOBALS['TSFE']->sys_page->getPage_noCheck($theRedirect);
548 $LD = $GLOBALS['TSFE']->tmpl->linkData($page, $target, $noCache, 'index.php', '', $this->cObj->getClosestMPvalueForPage($page['uid']));
549 } else {
550 // External URL, redirect-hidden field is rendered!
551 $LD = $GLOBALS['TSFE']->tmpl->linkData($page, $target, $noCache, '', '', $this->cObj->getClosestMPvalueForPage($page['uid']));
552 $LD['totalURL'] = $theRedirect;
553 $hiddenfields .= '<input type="hidden" name="redirect" value="' . htmlspecialchars($LD['totalURL']) . '" />';
554 }
555 // Formtype (where to submit to!):
556 if ($propertyOverride['type']) {
557 $formtype = $propertyOverride['type'];
558 } else {
559 $formtype = isset($conf['type.']) ? $this->cObj->stdWrap($conf['type'], $conf['type.']) : $conf['type'];
560 }
561 // Submit to a specific page
562 if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($formtype)) {
563 $page = $GLOBALS['TSFE']->sys_page->getPage_noCheck($formtype);
564 $LD_A = $GLOBALS['TSFE']->tmpl->linkData($page, $target, $noCache, '', '', $this->cObj->getClosestMPvalueForPage($page['uid']));
565 $action = $LD_A['totalURL'];
566 } elseif ($formtype) {
567 // Submit to external script
568 $LD_A = $LD;
569 $action = $formtype;
570 } elseif (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($theRedirect)) {
571 $LD_A = $LD;
572 $action = $LD_A['totalURL'];
573 } else {
574 // Submit to "nothing" - which is current page
575 $LD_A = $GLOBALS['TSFE']->tmpl->linkData($GLOBALS['TSFE']->page, $target, $noCache, '', '', $this->cObj->getClosestMPvalueForPage($page['uid']));
576 $action = $LD_A['totalURL'];
577 }
578 // Recipient:
579 $theEmail = isset($conf['recipient.']) ? $this->cObj->stdWrap($conf['recipient'], $conf['recipient.']) : $conf['recipient'];
580 if ($theEmail && !$GLOBALS['TYPO3_CONF_VARS']['FE']['secureFormmail']) {
581 $theEmail = $GLOBALS['TSFE']->codeString($theEmail);
582 $hiddenfields .= '<input type="hidden" name="recipient" value="' . htmlspecialchars($theEmail) . '" />';
583 }
584 // location data:
585 $location = isset($conf['locationData.']) ? $this->cObj->stdWrap($conf['locationData'], $conf['locationData.']) : $conf['locationData'];
586 if ($location) {
587 if ($location == 'HTTP_POST_VARS' && isset($_POST['locationData'])) {
588 $locationData = GeneralUtility::_POST('locationData');
589 } else {
590 // locationData is [the page id]:[tablename]:[uid of record]. Indicates on which page the record (from tablename with uid) is shown. Used to check access.
591 if (isset($this->data['_LOCALIZED_UID'])) {
592 $locationData = $GLOBALS['TSFE']->id . ':' . str_replace($this->data['uid'], $this->data['_LOCALIZED_UID'], $this->cObj->currentRecord);
593 } else {
594 $locationData = $GLOBALS['TSFE']->id . ':' . $this->cObj->currentRecord;
595 }
596 }
597 $hiddenfields .= '<input type="hidden" name="locationData" value="' . htmlspecialchars($locationData) . '" />';
598 }
599 // Hidden fields:
600 if (is_array($conf['hiddenFields.'])) {
601 foreach ($conf['hiddenFields.'] as $hF_key => $hF_conf) {
602 if (substr($hF_key, -1) != '.') {
603 $hF_value = $this->cObj->cObjGetSingle($hF_conf, $conf['hiddenFields.'][$hF_key . '.'], 'hiddenfields');
604 if (strlen($hF_value) && GeneralUtility::inList('recipient_copy,recipient', $hF_key)) {
605 if ($GLOBALS['TYPO3_CONF_VARS']['FE']['secureFormmail']) {
606 continue;
607 }
608 $hF_value = $GLOBALS['TSFE']->codeString($hF_value);
609 }
610 $hiddenfields .= '<input type="hidden" name="' . $hF_key . '" value="' . htmlspecialchars($hF_value) . '" />';
611 }
612 }
613 }
614 // Wrap all hidden fields in a div tag (see http://forge.typo3.org/issues/14491)
615 $hiddenfields = isset($conf['hiddenFields.']['stdWrap.']) ? $this->cObj->stdWrap($hiddenfields, $conf['hiddenFields.']['stdWrap.']) : '<div style="display:none;">' . $hiddenfields . '</div>';
616 if ($conf['REQ']) {
617 $goodMess = isset($conf['goodMess.']) ? $this->cObj->stdWrap($conf['goodMess'], $conf['goodMess.']) : $conf['goodMess'];
618 $badMess = isset($conf['badMess.']) ? $this->cObj->stdWrap($conf['badMess'], $conf['badMess.']) : $conf['badMess'];
619 $emailMess = isset($conf['emailMess.']) ? $this->cObj->stdWrap($conf['emailMess'], $conf['emailMess.']) : $conf['emailMess'];
620 $validateForm = ' onsubmit="return validateForm(' . GeneralUtility::quoteJSvalue($formName) . ',' . GeneralUtility::quoteJSvalue(implode(',', $fieldlist)) . ',' . GeneralUtility::quoteJSvalue($goodMess) . ',' . GeneralUtility::quoteJSvalue($badMess) . ',' . GeneralUtility::quoteJSvalue($emailMess) . ')"';
621 $GLOBALS['TSFE']->additionalHeaderData['JSFormValidate'] = '<script type="text/javascript" src="' . GeneralUtility::createVersionNumberedFilename(($GLOBALS['TSFE']->absRefPrefix . 'typo3/sysext/frontend/Resources/Public/JavaScript/jsfunc.validateform.js')) . '"></script>';
622 } else {
623 $validateForm = '';
624 }
625 // Create form tag:
626 $theTarget = $theRedirect ? $LD['target'] : $LD_A['target'];
627 $method = isset($conf['method.']) ? $this->cObj->stdWrap($conf['method'], $conf['method.']) : $conf['method'];
628 $content = array(
629 '<form' . ' action="' . htmlspecialchars($action) . '"' . ' id="' . $formName . '"' . ($xhtmlStrict ? '' : ' name="' . $formName . '"') . ' enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '"' . ' method="' . ($method ? $method : 'post') . '"' . ($theTarget ? ' target="' . $theTarget . '"' : '') . $validateForm . '>',
630 $hiddenfields . $content,
631 '</form>'
632 );
633 $arrayReturnMode = isset($conf['arrayReturnMode.']) ? $this->cObj->stdWrap($conf['arrayReturnMode'], $conf['arrayReturnMode.']) : $conf['arrayReturnMode'];
634 if ($arrayReturnMode) {
635 $content['validateForm'] = $validateForm;
636 $content['formname'] = $formName;
637 return $content;
638 } else {
639 return implode('', $content);
640 }
641 }
642
643 }