Cleanup: Updated copyright comments
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / content / class.tslib_content_form.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010-2011 Xavier Perseguers <typo3@perseguers.ch>
6 * (c) 2010-2011 Steffen Kamper <steffen@typo3.org>
7 * All rights reserved
8 *
9 * This script is part of the TYPO3 project. The TYPO3 project is
10 * free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * The GNU General Public License can be found at
16 * http://www.gnu.org/copyleft/gpl.html.
17 * A copy is found in the textfile GPL.txt and important notices to the license
18 * from the author is found in LICENSE.txt distributed with these scripts.
19 *
20 *
21 * This script is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * This copyright notice MUST APPEAR in all copies of the script!
27 ***************************************************************/
28
29 /**
30 * Contains FORM class object.
31 *
32 * $Id: class.tslib_content.php 7905 2010-06-13 14:42:33Z ohader $
33 * @author Xavier Perseguers <typo3@perseguers.ch>
34 * @author Steffen Kamper <steffen@typo3.org>
35 */
36 class tslib_content_Form extends tslib_content_Abstract {
37
38 /**
39 * Rendering the cObject, FORM
40 *
41 * Note on $formData:
42 * In the optional $formData array each entry represents a line in the ordinary setup.
43 * In those entries each entry (0,1,2...) represents a space normally divided by the '|' line.
44 *
45 * $formData [] = array('Name:', 'name=input, 25 ', 'Default value....');
46 * $formData [] = array('Email:', 'email=input, 25 ', 'Default value for email....');
47 *
48 * - corresponds to the $conf['data'] value being :
49 * Name:|name=input, 25 |Default value....||Email:|email=input, 25 |Default value for email....
50 *
51 * If $formData is an array the value of $conf['data'] is ignored.
52 *
53 * @param array Array of TypoScript properties
54 * @param array Alternative formdata overriding whatever comes from TypoScript
55 * @return string Output
56 */
57 public function render($conf = array(), $formData = '') {
58 $content = '';
59 if (is_array($formData)) {
60 $dataArray = $formData;
61 } else {
62 $data = isset($conf['data.'])
63 ? $this->cObj->stdWrap($conf['data'], $conf['data.'])
64 : $conf['data'];
65 // Clearing dataArr
66 $dataArray = array();
67 // Getting the original config
68 if (trim($data)) {
69 $data = str_replace(LF, '||', $data);
70 $dataArray = explode('||', $data);
71 }
72 // Adding the new dataArray config form:
73 if (is_array($conf['dataArray.'])) { // dataArray is supplied
74 $sortedKeyArray = t3lib_TStemplate::sortedKeyList($conf['dataArray.'], TRUE);
75 foreach ($sortedKeyArray as $theKey) {
76 $singleKeyArray = $conf['dataArray.'][$theKey . '.'];
77 if (is_array($singleKeyArray)) {
78 $temp = array();
79 $label = isset($singleKeyArray['label.'])
80 ? $this->cObj->stdWrap($singleKeyArray['label'], $singleKeyArray['label.'])
81 : $singleKeyArray['label'];
82 list ($temp[0]) = explode('|', $label);
83 $type = isset($singleKeyArray['type.'])
84 ? $this->cObj->stdWrap($singleKeyArray['type'],$singleKeyArray['type.'])
85 : $singleKeyArray['type'];
86 list ($temp[1]) = explode('|', $type);
87 $required = isset($singleKeyArray['required.'])
88 ? $this->cObj->stdWrap($singleKeyArray['required'], $singleKeyArray['required.'])
89 : $singleKeyArray['required'];
90 if ($required) {
91 $temp[1] = '*' . $temp[1];
92 }
93 $singleValue = isset($singleKeyArray['value.'])
94 ? $this->cObj->stdWrap($singleKeyArray['value'], $singleKeyArray['value.'])
95 : $singleKeyArray['value'];
96 list ($temp[2]) = explode('|', $singleValue);
97 // If value array is set, then implode those values.
98 if (is_array($singleKeyArray['valueArray.'])) {
99 $temp_accumulated = array();
100 foreach ($singleKeyArray['valueArray.'] as $singleKey => $singleKey_valueArray) {
101 if (is_array($singleKey_valueArray) && !strcmp(intval($singleKey) . '.', $singleKey)) {
102 $temp_valueArray = array();
103 $valueArrayLabel = isset($singleKey_valueArray['label.'])
104 ? $this->cObj->stdWrap($singleKey_valueArray['label'], $singleKey_valueArray['label.'])
105 : $singleKey_valueArray['label'];
106 list ($temp_valueArray[0]) = explode('=', $valueArrayLabel);
107 $selected = isset($singleKeyArray['selected.'])
108 ? $this->cObj->stdWrap($singleKeyArray['selected'], $singleKeyArray['selected.'])
109 : $singleKeyArray['selected'];
110 if ($selected) {
111 $temp_valueArray[0] = '*' . $temp_valueArray[0];
112 }
113 $singleKeyValue = isset($singleKey_valueArray['value.'])
114 ? $this->cObj->stdWrap($singleKey_valueArray['value'], $singleKey_valueArray['value.'])
115 : $singleKey_valueArray['value'];
116 list ($temp_valueArray[1]) = explode(',', $singleKeyValue);
117 }
118 $temp_accumulated[] = implode('=', $temp_valueArray);
119 }
120 $temp[2] = implode(',', $temp_accumulated);
121 }
122 $specialEval = isset($singleKeyArray['specialEval.'])
123 ? $this->cObj->stdWrap($singleKeyArray['specialEval'], $singleKeyArray['specialEval.'])
124 : $singleKeyArray['specialEval'];
125 list ($temp[3]) = explode('|', $specialEval);
126
127 // adding the form entry to the dataArray
128 $dataArray[] = implode('|', $temp);
129 }
130 }
131 }
132 }
133
134 $attachmentCounter = '';
135 $hiddenfields = '';
136 $fieldlist = array();
137 $propertyOverride = array();
138 $fieldname_hashArray = array();
139 $counter = 0;
140
141 $xhtmlStrict = t3lib_div::inList('xhtml_strict,xhtml_11,xhtml_2', $GLOBALS['TSFE']->xhtmlDoctype);
142 // Formname
143 $formName = isset($conf['formName.'])
144 ? $this->cObj->stdWrap($conf['formName'], $conf['formName.'])
145 : $conf['formName'];
146 if ($formName) {
147 $formName = $this->cObj->cleanFormName($formName);
148 } else {
149 $formName = 'a' . $GLOBALS['TSFE']->uniqueHash(); // form name has to start with a letter to reach XHTML compliance
150 }
151
152 $fieldPrefix = isset($conf['fieldPrefix.'])
153 ? $this->cObj->stdWrap($conf['fieldPrefix'], $conf['fieldPrefix.'])
154 : $conf['fieldPrefix'];
155 if (isset($conf['fieldPrefix']) || isset($conf['fieldPrefix.'])) {
156 if ($fieldPrefix) {
157 $prefix = $this->cObj->cleanFormName($fieldPrefix);
158 } else {
159 $prefix = '';
160 }
161 } else {
162 $prefix = $formName;
163 }
164
165 foreach ($dataArray as $dataValue) {
166
167 $counter++;
168 $confData = array();
169 if (is_array($formData)) {
170 $parts = $dataValue;
171 $dataValue = 1; // TRUE...
172 } else {
173 $dataValue = trim($dataValue);
174 $parts = explode('|', $dataValue);
175 }
176 if ($dataValue && strcspn($dataValue, '#/')) {
177 // label:
178 $confData['label'] = t3lib_div::removeXSS(trim($parts[0]));
179 // field:
180 $fParts = explode(',', $parts[1]);
181 $fParts[0] = trim($fParts[0]);
182 if (substr($fParts[0], 0, 1) == '*') {
183 $confData['required'] = 1;
184 $fParts[0] = substr($fParts[0], 1);
185 }
186 $typeParts = explode('=', $fParts[0]);
187 $confData['type'] = trim(strtolower(end($typeParts)));
188 if (count($typeParts) == 1) {
189 $confData['fieldname'] = $this->cObj->cleanFormName($parts[0]);
190 if (strtolower(preg_replace('/[^[:alnum:]]/', '', $confData['fieldname'])) == 'email') {
191 $confData['fieldname'] = 'email';
192 }
193 // Duplicate fieldnames resolved
194 if (isset($fieldname_hashArray[md5($confData['fieldname'])])) {
195 $confData['fieldname'] .= '_' . $counter;
196 }
197 $fieldname_hashArray[md5($confData['fieldname'])] = $confData['fieldname'];
198 // Attachment names...
199 if ($confData['type'] == 'file') {
200 $confData['fieldname'] = 'attachment' . $attachmentCounter;
201 $attachmentCounter = intval($attachmentCounter) + 1;
202 }
203 } else {
204 $confData['fieldname'] = str_replace(' ', '_', trim($typeParts[0]));
205 }
206 $confData['fieldname'] = htmlspecialchars($confData['fieldname']);
207 $fieldCode = '';
208
209 $wrapFieldName = isset($conf['wrapFieldName'])
210 ? $this->cObj->stdWrap($conf['wrapFieldName'], $conf['wrapFieldName.'])
211 : $conf['wrapFieldName'];
212 if ($wrapFieldName) {
213 $confData['fieldname'] = $this->cObj->wrap($confData['fieldname'], $wrapFieldName);
214 }
215
216 // Set field name as current:
217 $this->cObj->setCurrentVal($confData['fieldname']);
218
219 // Additional parameters
220 if (trim($confData['type'])) {
221 if (isset($conf['params.'][$confData['type']])) {
222 $addParams = isset($conf['params.'][$confData['type'] . '.'])
223 ? trim($this->cObj->stdWrap($conf['params.'][$confData['type']], $conf['params.'][$confData['type'] . '.']))
224 : trim($conf['params.'][$confData['type']]);
225 } else {
226 $addParams = isset($conf['params.'])
227 ? trim($this->cObj->stdWrap($conf['params'], $conf['params.']))
228 : trim($conf['params']);
229 }
230 if (strcmp('', $addParams)) {
231 $addParams = ' ' . $addParams;
232 }
233 } else
234 $addParams = '';
235
236 $dontMd5FieldNames = isset($conf['dontMd5FieldNames.'])
237 ? $this->cObj->stdWrap($conf['dontMd5FieldNames'], $conf['dontMd5FieldNames.'])
238 : $conf['dontMd5FieldNames'];
239 if ($dontMd5FieldNames) {
240 $fName = $confData['fieldname'];
241 } else {
242 $fName = md5($confData['fieldname']);
243 }
244
245 // Accessibility: Set id = fieldname attribute:
246 $accessibility = isset($conf['accessibility.'])
247 ? $this->cObj->stdWrap($conf['accessibility'], $conf['accessibility.'])
248 : $conf['accessibility'];
249 if ($accessibility || $xhtmlStrict) {
250 $elementIdAttribute = ' id="' . $prefix . $fName . '"';
251 } else {
252 $elementIdAttribute = '';
253 }
254
255 // Create form field based on configuration/type:
256 switch ($confData['type']) {
257 case 'textarea' :
258 $cols = trim($fParts[1]) ? intval($fParts[1]) : 20;
259 $compensateFieldWidth = isset($conf['compensateFieldWidth.'])
260 ? $this->cObj->stdWrap($conf['compensateFieldWidth'], $conf['compensateFieldWidth.'])
261 : $conf['compensateFieldWidth'];
262 $compWidth = doubleval($compensateFieldWidth
263 ? $compensateFieldWidth
264 : $GLOBALS['TSFE']->compensateFieldWidth
265 );
266 $compWidth = $compWidth ? $compWidth : 1;
267 $cols = t3lib_div::intInRange($cols * $compWidth, 1, 120);
268
269 $rows = trim($fParts[2]) ? t3lib_div::intInRange($fParts[2], 1, 30) : 5;
270 $wrap = trim($fParts[3]);
271 $noWrapAttr = isset($conf['noWrapAttr.'])
272 ? $this->cObj->stdWrap($conf['noWrapAttr'], $conf['noWrapAttr.'])
273 : $conf['noWrapAttr'];
274 if ($noWrapAttr || $wrap === 'disabled') {
275 $wrap = '';
276 } else {
277 $wrap = $wrap ? ' wrap="' . $wrap . '"' : ' wrap="virtual"';
278 }
279 $noValueInsert = isset($conf['noValueInsert.'])
280 ? $this->cObj->stdWrap($conf['noValueInsert'], $conf['noValueInsert.'])
281 : $conf['noValueInsert'];
282 $default = $this->cObj->getFieldDefaultValue(
283 $noValueInsert,
284 $confData['fieldname'],
285 str_replace('\n', LF, trim($parts[2]))
286 );
287 $fieldCode = sprintf(
288 '<textarea name="%s"%s cols="%s" rows="%s"%s%s>%s</textarea>',
289 $confData['fieldname'],
290 $elementIdAttribute,
291 $cols,
292 $rows,
293 $wrap,
294 $addParams,
295 t3lib_div::formatForTextarea($default)
296 );
297 break;
298 case 'input' :
299 case 'password' :
300 $size = trim($fParts[1]) ? intval($fParts[1]) : 20;
301 $compensateFieldWidth = isset($conf['compensateFieldWidth.'])
302 ? $this->cObj->stdWrap($conf['compensateFieldWidth'], $conf['compensateFieldWidth.'])
303 : $conf['compensateFieldWidth'];
304 $compWidth = doubleval($compensateFieldWidth
305 ? $compensateFieldWidth
306 : $GLOBALS['TSFE']->compensateFieldWidth
307 );
308 $compWidth = $compWidth ? $compWidth : 1;
309 $size = t3lib_div::intInRange($size * $compWidth, 1, 120);
310 $noValueInsert = isset($conf['noValueInsert.'])
311 ? $this->cObj->stdWrap($conf['noValueInsert'], $conf['noValueInsert.'])
312 : $conf['noValueInsert'];
313 $default = $this->cObj->getFieldDefaultValue(
314 $noValueInsert,
315 $confData['fieldname'],
316 trim($parts[2])
317 );
318
319 if ($confData['type'] == 'password') {
320 $default = '';
321 }
322
323 $max = trim($fParts[2]) ? ' maxlength="' . t3lib_div::intInRange($fParts[2], 1, 1000) . '"' : "";
324 $theType = $confData['type'] == 'input' ? 'text' : 'password';
325
326 $fieldCode = sprintf(
327 '<input type="%s" name="%s"%s size="%s"%s value="%s"%s />',
328 $theType,
329 $confData['fieldname'],
330 $elementIdAttribute,
331 $size,
332 $max,
333 htmlspecialchars($default),
334 $addParams
335 );
336
337 break;
338 case 'file' :
339 $size = trim($fParts[1]) ? t3lib_div::intInRange($fParts[1], 1, 60) : 20;
340 $fieldCode = sprintf(
341 '<input type="file" name="%s"%s size="%s"%s />',
342 $confData['fieldname'],
343 $elementIdAttribute,
344 $size,
345 $addParams
346 );
347 break;
348 case 'check' :
349 // alternative default value:
350 $noValueInsert = isset($conf['noValueInsert.'])
351 ? $this->cObj->stdWrap($conf['noValueInsert'], $conf['noValueInsert.'])
352 : $conf['noValueInsert'];
353 $default = $this->cObj->getFieldDefaultValue(
354 $noValueInsert,
355 $confData['fieldname'],
356 trim($parts[2])
357 );
358 $checked = $default ? ' checked="checked"' : '';
359 $fieldCode = sprintf(
360 '<input type="checkbox" value="%s" name="%s"%s%s%s />',
361 1,
362 $confData['fieldname'],
363 $elementIdAttribute,
364 $checked,
365 $addParams
366 );
367 break;
368 case 'select' :
369 $option = '';
370 $valueParts = explode(',', $parts[2]);
371 // size
372 if (strtolower(trim($fParts[1])) == 'auto') {
373 $fParts[1] = count($valueParts);
374 } // Auto size set here. Max 20
375 $size = trim($fParts[1]) ? t3lib_div::intInRange($fParts[1], 1, 20) : 1;
376 // multiple
377 $multiple = strtolower(trim($fParts[2])) == 'm' ? ' multiple="multiple"' : '';
378
379 $items = array(); // Where the items will be
380 $defaults = array(); //RTF
381 $pCount = count($valueParts);
382 for ($a = 0; $a < $pCount; $a++) {
383 $valueParts[$a] = trim($valueParts[$a]);
384 if (substr($valueParts[$a], 0, 1) == '*') { // Finding default value
385 $sel = 'selected';
386 $valueParts[$a] = substr($valueParts[$a], 1);
387 } else
388 $sel = '';
389 // Get value/label
390 $subParts = explode('=', $valueParts[$a]);
391 $subParts[1] = (isset($subParts[1]) ? trim($subParts[1]) : trim($subParts[0])); // Sets the value
392 $items[] = $subParts; // Adds the value/label pair to the items-array
393 if ($sel) {
394 $defaults[] = $subParts[1];
395 } // Sets the default value if value/label pair is marked as default.
396 }
397 // alternative default value:
398 $noValueInsert = isset($conf['noValueInsert.'])
399 ? $this->cObj->stdWrap($conf['noValueInsert'], $conf['noValueInsert.'])
400 : $conf['noValueInsert'];
401 $default = $this->cObj->getFieldDefaultValue(
402 $noValueInsert,
403 $confData['fieldname'],
404 $defaults
405 );
406 if (!is_array($default)) {
407 $defaults = array();
408 $defaults[] = $default;
409 } else {
410 $defaults = $default;
411 }
412 // Create the select-box:
413 $iCount = count($items);
414 for ($a = 0; $a < $iCount; $a++) {
415 $option .= '<option value="' . $items[$a][1] . '"' . (in_array($items[$a][1], $defaults) ? ' selected="selected"' : '') . '>' . trim($items[$a][0]) . '</option>'; //RTF
416 }
417
418 if ($multiple) {
419 // 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.
420 $confData['fieldname'] .= '[]';
421 }
422 $fieldCode = sprintf(
423 '<select name="%s"%s size="%s"%s%s>%s</select>',
424 $confData['fieldname'],
425 $elementIdAttribute,
426 $size,
427 $multiple,
428 $addParams,
429 $option
430 ); //RTF
431 break;
432 case 'radio' :
433 $option = '';
434
435 $valueParts = explode(',', $parts[2]);
436 $items = array(); // Where the items will be
437 $default = '';
438 $pCount = count($valueParts);
439 for ($a = 0; $a < $pCount; $a++) {
440 $valueParts[$a] = trim($valueParts[$a]);
441 if (substr($valueParts[$a], 0, 1) == '*') {
442 $sel = 'checked';
443 $valueParts[$a] = substr($valueParts[$a], 1);
444 } else
445 $sel = '';
446 // Get value/label
447 $subParts = explode('=', $valueParts[$a]);
448 $subParts[1] = (isset($subParts[1]) ? trim($subParts[1]) : trim($subParts[0])); // Sets the value
449 $items[] = $subParts; // Adds the value/label pair to the items-array
450 if ($sel) {
451 $default = $subParts[1];
452 } // Sets the default value if value/label pair is marked as default.
453 }
454 // alternative default value:
455 $noValueInsert = isset($conf['noValueInsert.'])
456 ? $this->cObj->stdWrap($conf['noValueInsert'], $conf['noValueInsert.'])
457 : $conf['noValueInsert'];
458 $default = $this->cObj->getFieldDefaultValue(
459 $noValueInsert,
460 $confData['fieldname'],
461 $default
462 );
463 // Create the select-box:
464 $iCount = count($items);
465 for ($a = 0; $a < $iCount; $a++) {
466 $optionParts = '';
467 $radioId = $prefix . $fName . $this->cObj->cleanFormName($items[$a][0]);
468 if ($accessibility) {
469 $radioLabelIdAttribute = ' id="' . $radioId . '"';
470 } else {
471 $radioLabelIdAttribute = '';
472 }
473 $optionParts .= '<input type="radio" name="' . $confData['fieldname'] . '"' .
474 $radioLabelIdAttribute . ' value="' . $items[$a][1] . '"' .
475 (!strcmp($items[$a][1], $default) ? ' checked="checked"' : '') . $addParams . ' />';
476 if ($accessibility) {
477 $label = isset($conf['radioWrap.'])
478 ? $this->cObj->stdWrap(trim($items[$a][0]), $conf['radioWrap.'])
479 : trim($items[$a][0]);
480 $optionParts .= '<label for="' . $radioId . '">' . $label . '</label>';
481 } else {
482 $optionParts .= isset($conf['radioWrap.'])
483 ? $this->cObj->stdWrap(trim($items[$a][0]), $conf['radioWrap.'])
484 : trim($items[$a][0]);
485 }
486 $option .= isset($conf['radioInputWrap.'])
487 ? $this->cObj->stdWrap($optionParts, $conf['radioInputWrap.'])
488 : $optionParts;
489 }
490
491 if ($accessibility) {
492 $accessibilityWrap = isset($conf['radioWrap.']['accessibilityWrap.'])
493 ? $this->cObj->stdWrap($conf['radioWrap.']['accessibilityWrap'], $conf['radioWrap.']['accessibilityWrap.'])
494 : $conf['radioWrap.']['accessibilityWrap.'];
495
496 if($accessibilityWrap) {
497 $search = array(
498 '###RADIO_FIELD_ID###', '###RADIO_GROUP_LABEL###'
499 );
500 $replace = array(
501 $elementIdAttribute, $confData['label']
502 );
503 $accessibilityWrap = str_replace($search, $replace, $accessibilityWrap);
504
505 $option = $this->cObj->wrap($option, $accessibilityWrap);
506 }
507 }
508
509 $fieldCode = $option;
510 break;
511 case 'hidden' :
512 $value = trim($parts[2]);
513
514 // If this form includes an auto responder message, include a HMAC checksum field
515 // in order to verify potential abuse of this feature.
516 if (strlen($value) && t3lib_div::inList($confData['fieldname'], 'auto_respond_msg')) {
517 $hmacChecksum = t3lib_div::hmac($value);
518 $hiddenfields .= sprintf(
519 '<input type="hidden" name="auto_respond_checksum" id="%sauto_respond_checksum" value="%s" />',
520 $prefix,
521 $hmacChecksum
522 );
523 }
524
525 if (strlen($value) && t3lib_div::inList('recipient_copy,recipient',
526 $confData['fieldname']) && $GLOBALS['TYPO3_CONF_VARS']['FE']['secureFormmail']) {
527 break;
528 }
529 if (strlen($value) && t3lib_div::inList('recipient_copy,recipient', $confData['fieldname'])) {
530 $value = $GLOBALS['TSFE']->codeString($value);
531 }
532 $hiddenfields .= sprintf(
533 '<input type="hidden" name="%s"%s value="%s" />',
534 $confData['fieldname'],
535 $elementIdAttribute,
536 htmlspecialchars($value)
537 );
538 break;
539 case 'property' :
540 if (t3lib_div::inList('type,locationData,goodMess,badMess,emailMess', $confData['fieldname'])) {
541 $value = trim($parts[2]);
542 $propertyOverride[$confData['fieldname']] = $value;
543 $conf[$confData['fieldname']] = $value;
544 }
545 break;
546 case 'submit' :
547 $value = trim($parts[2]);
548 if ($conf['image.']) {
549 $this->cObj->data[$this->cObj->currentValKey] = $value;
550 $image = $this->cObj->IMG_RESOURCE($conf['image.']);
551 $params = $conf['image.']['params'] ? ' ' . $conf['image.']['params'] : '';
552 $params .= $this->cObj->getAltParam($conf['image.'], FALSE);
553 $params .= $addParams;
554 } else {
555 $image = '';
556 }
557 if ($image) {
558 $fieldCode = sprintf(
559 '<input type="image" name="%s"%s src="%s"%s />',
560 $confData['fieldname'],
561 $elementIdAttribute,
562 $image,
563 $params
564 );
565 } else {
566 $fieldCode = sprintf(
567 '<input type="submit" name="%s"%s value="%s"%s />',
568 $confData['fieldname'],
569 $elementIdAttribute,
570 t3lib_div::deHSCentities(htmlspecialchars($value)),
571 $addParams
572 );
573 }
574 break;
575 case 'reset' :
576 $value = trim($parts[2]);
577 $fieldCode = sprintf(
578 '<input type="reset" name="%s"%s value="%s"%s />',
579 $confData['fieldname'],
580 $elementIdAttribute,
581 t3lib_div::deHSCentities(htmlspecialchars($value)),
582 $addParams
583 );
584 break;
585 case 'label' :
586 $fieldCode = nl2br(htmlspecialchars(trim($parts[2])));
587 break;
588 default :
589 $confData['type'] = 'comment';
590 $fieldCode = trim($parts[2]) . '&nbsp;';
591 break;
592 }
593 if ($fieldCode) {
594
595 // Checking for special evaluation modes:
596 if (t3lib_div::inList('textarea,input,password', $confData['type']) && strlen(trim($parts[3]))) {
597 $modeParameters = t3lib_div::trimExplode(':', $parts[3]);
598 } else {
599 $modeParameters = array();
600 }
601
602 // Adding evaluation based on settings:
603 switch ((string) $modeParameters[0]) {
604 case 'EREG' :
605 $fieldlist[] = '_EREG';
606 $fieldlist[] = $modeParameters[1];
607 $fieldlist[] = $modeParameters[2];
608 $fieldlist[] = $confData['fieldname'];
609 $fieldlist[] = $confData['label'];
610 $confData['required'] = 1; // Setting this so "required" layout is used.
611 break;
612 case 'EMAIL' :
613 $fieldlist[] = '_EMAIL';
614 $fieldlist[] = $confData['fieldname'];
615 $fieldlist[] = $confData['label'];
616 $confData['required'] = 1; // Setting this so "required" layout is used.
617 break;
618 default :
619 if ($confData['required']) {
620 $fieldlist[] = $confData['fieldname'];
621 $fieldlist[] = $confData['label'];
622 }
623 break;
624 }
625
626 // Field:
627 $fieldLabel = $confData['label'];
628 if ($accessibility && trim($fieldLabel) && !preg_match('/^(label|hidden|comment)$/', $confData['type'])) {
629 $fieldLabel = '<label for="' . $prefix . $fName . '">' . $fieldLabel . '</label>';
630 }
631
632 // Getting template code:
633 if(isset($conf['fieldWrap.'])) {
634 $fieldCode = $this->cObj->stdWrap($fieldCode, $conf['fieldWrap.']);
635 }
636 $labelCode = isset($conf['labelWrap.'])
637 ? $this->cObj->stdWrap($fieldLabel, $conf['labelWrap.'])
638 : $fieldLabel;
639 $commentCode = isset($conf['commentWrap.'])
640 ? $this->cObj->stdWrap($confData['label'], $conf['commentWrap.']) // RTF
641 : $confData['label'];
642 $result = $conf['layout'];
643 $req = isset($conf['REQ.'])
644 ? $this->cObj->stdWrap($conf['REQ'], $conf['REQ.'])
645 : $conf['REQ'];
646 if ($req && $confData['required']) {
647 if (isset($conf['REQ.']['fieldWrap.'])) {
648 $fieldCode = $this->cObj->stdWrap($fieldCode, $conf['REQ.']['fieldWrap.']);
649 }
650 if (isset($conf['REQ.']['labelWrap.'])) {
651 $labelCode = $this->cObj->stdWrap($fieldLabel, $conf['REQ.']['labelWrap.']);
652 }
653 $reqLayout = isset($conf['REQ.']['layout.'])
654 ? $this->cObj->stdWrap($conf['REQ.']['layout'], $conf['REQ.']['layout.'])
655 : $conf['REQ.']['layout'];
656 if ($reqLayout) {
657 $result = $reqLayout;
658 }
659 }
660 if ($confData['type'] == 'comment') {
661 $commentLayout = isset($conf['COMMENT.']['layout.'])
662 ? $this->cObj->stdWrap($conf['COMMENT.']['layout'], $conf['COMMENT.']['layout.'])
663 : $conf['COMMENT.']['layout'];
664 if ($commentLayout) {
665 $result = $commentLayout;
666 }
667 }
668 if ($confData['type'] == 'check') {
669 $checkLayout = isset($conf['CHECK.']['layout.'])
670 ? $this->cObj->stdWrap($conf['CHECK.']['layout'], $conf['CHECK.']['layout.'])
671 : $conf['CHECK.']['layout'];
672 if ($checkLayout) {
673 $result = $checkLayout;
674 }
675 }
676 if ($confData['type'] == 'radio') {
677 $radioLayout = isset($conf['RADIO.']['layout.'])
678 ? $this->cObj->stdWrap($conf['RADIO.']['layout'], $conf['RADIO.']['layout.'])
679 : $conf['RADIO.']['layout'];
680 if ($radioLayout) {
681 $result = $radioLayout;
682 }
683 }
684 if ($confData['type'] == 'label') {
685 $labelLayout = isset($conf['LABEL.']['layout.'])
686 ? $this->cObj->stdWrap($conf['LABEL.']['layout'], $conf['LABEL.']['layout.'])
687 : $conf['CHECK.']['layout'];
688 if ($labelLayout) {
689 $result = $labelLayout;
690 }
691 }
692 $result = str_replace('###FIELD###', $fieldCode, $result);
693 $result = str_replace('###LABEL###', $labelCode, $result);
694 $result = str_replace('###COMMENT###', $commentCode, $result); //RTF
695 $content .= $result;
696 }
697 }
698 }
699 if (isset($conf['stdWrap.'])) {
700 $content = $this->cObj->stdWrap($content, $conf['stdWrap.']);
701 }
702
703
704 // redirect (external: where to go afterwards. internal: where to submit to)
705 $theRedirect = isset($conf['redirect.'])
706 ? $this->cObj->stdWrap($conf['redirect'], $conf['redirect.'])
707 : $conf['redirect']; // 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)
708 $target = isset($conf['target.'])
709 ? $this->cObj->stdWrap($conf['target'], $conf['target.'])
710 : $conf['target']; // 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)
711 $noCache = isset($conf['no_cache.'])
712 ? $this->cObj->stdWrap($conf['no_cache'], $conf['no_cache.'])
713 : $conf['no_cache']; // 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)
714 $page = $GLOBALS['TSFE']->page;
715 if (!$theRedirect) { // Internal: Just submit to current page
716 $LD = $GLOBALS['TSFE']->tmpl->linkData(
717 $page,
718 $target,
719 $noCache,
720 'index.php',
721 '',
722 $this->cObj->getClosestMPvalueForPage($page['uid'])
723 );
724 } elseif (t3lib_div::testInt($theRedirect)) { // Internal: Submit to page with ID $theRedirect
725 $page = $GLOBALS['TSFE']->sys_page->getPage_noCheck($theRedirect);
726 $LD = $GLOBALS['TSFE']->tmpl->linkData(
727 $page,
728 $target,
729 $noCache,
730 'index.php',
731 '',
732 $this->cObj->getClosestMPvalueForPage($page['uid'])
733 );
734 } else { // External URL, redirect-hidden field is rendered!
735 $LD = $GLOBALS['TSFE']->tmpl->linkData(
736 $page,
737 $target,
738 $noCache,
739 '',
740 '',
741 $this->cObj->getClosestMPvalueForPage($page['uid'])
742 );
743 $LD['totalURL'] = $theRedirect;
744 $hiddenfields .= '<input type="hidden" name="redirect" value="' . htmlspecialchars($LD['totalURL']) . '" />'; // 18-09-00 added
745 }
746
747 // Formtype (where to submit to!):
748 if($propertyOverride['type']) {
749 $formtype = $propertyOverride['type'];
750 } else {
751 $formtype = isset($conf['type.'])
752 ? $this->cObj->stdWrap($conf['type'], $conf['type.'])
753 : $conf['type'];
754 }
755 if (t3lib_div::testInt($formtype)) { // Submit to a specific page
756 $page = $GLOBALS['TSFE']->sys_page->getPage_noCheck($formtype);
757 $LD_A = $GLOBALS['TSFE']->tmpl->linkData(
758 $page,
759 $target,
760 $noCache,
761 '',
762 '',
763 $this->cObj->getClosestMPvalueForPage($page['uid'])
764 );
765 $action = $LD_A['totalURL'];
766 } elseif ($formtype) { // Submit to external script
767 $LD_A = $LD;
768 $action = $formtype;
769 } elseif (t3lib_div::testInt($theRedirect)) {
770 $LD_A = $LD;
771 $action = $LD_A['totalURL'];
772 } else { // Submit to "nothing" - which is current page
773 $LD_A = $GLOBALS['TSFE']->tmpl->linkData(
774 $GLOBALS['TSFE']->page,
775 $target,
776 $noCache,
777 '',
778 '',
779 $this->cObj->getClosestMPvalueForPage($page['uid'])
780 );
781 $action = $LD_A['totalURL'];
782 }
783
784 // Recipient:
785 $theEmail = isset($conf['recipient.'])
786 ? $this->cObj->stdWrap($conf['recipient'], $conf['recipient.'])
787 : $conf['recipient'];
788 if ($theEmail && !$GLOBALS['TYPO3_CONF_VARS']['FE']['secureFormmail']) {
789 $theEmail = $GLOBALS['TSFE']->codeString($theEmail);
790 $hiddenfields .= '<input type="hidden" name="recipient" value="' . htmlspecialchars($theEmail) . '" />';
791 }
792
793 // location data:
794 $location = isset($conf['locationData.'])
795 ? $this->cObj->stdWrap($conf['locationData'], $conf['locationData.'])
796 : $conf['locationData'];
797 if ($location) {
798 if ($location == 'HTTP_POST_VARS' && isset($_POST['locationData'])) {
799 $locationData = t3lib_div::_POST('locationData');
800 } else {
801 // locationData is [hte page id]:[tablename]:[uid of record]. Indicates on which page the record (from tablename with uid) is shown. Used to check access.
802 $locationData = $GLOBALS['TSFE']->id . ':' . $this->cObj->currentRecord;
803 }
804 $hiddenfields .= '<input type="hidden" name="locationData" value="' . htmlspecialchars($locationData) . '" />';
805 }
806
807 // hidden fields:
808 if (is_array($conf['hiddenFields.'])) {
809 foreach ($conf['hiddenFields.'] as $hF_key => $hF_conf) {
810 if (substr($hF_key, -1) != '.') {
811 $hF_value = $this->cObj->cObjGetSingle($hF_conf, $conf['hiddenFields.'][$hF_key . '.'], 'hiddenfields');
812 if (strlen($hF_value) && t3lib_div::inList('recipient_copy,recipient', $hF_key)) {
813 if ($GLOBALS['TYPO3_CONF_VARS']['FE']['secureFormmail']) {
814 continue;
815 }
816 $hF_value = $GLOBALS['TSFE']->codeString($hF_value);
817 }
818 $hiddenfields .= '<input type="hidden" name="' . $hF_key . '" value="' . htmlspecialchars($hF_value) . '" />';
819 }
820 }
821 }
822
823 // Wrap all hidden fields in a div tag (see http://bugs.typo3.org/view.php?id=678)
824 $hiddenfields = isset($conf['hiddenFields.']['stdWrap.'])
825 ? $this->cObj->stdWrap($hiddenfields, $conf['hiddenFields.']['stdWrap.'])
826 : '<div style="display:none;">' . $hiddenfields . '</div>';
827
828 if ($conf['REQ']) {
829 $goodMess = isset($conf['goodMess.'])
830 ? $this->cObj->stdWrap($conf['goodMess'], $conf['goodMess.'])
831 : $conf['goodMess'];
832 $badMess = isset($conf['badMess.'])
833 ? $this->cObj->stdWrap($conf['badMess'], $conf['badMess.'])
834 : $conf['badMess'];
835 $emailMess = isset($conf['emailMess.'])
836 ? $this->cObj->stdWrap($conf['emailMess'], $conf['emailMess.'])
837 : $conf['emailMess'];
838 $validateForm = ' onsubmit="return validateForm(\'' . $formName . '\',\'' . implode(',', $fieldlist)
839 . '\',' . t3lib_div::quoteJSvalue($goodMess) . ',' .
840 t3lib_div::quoteJSvalue($badMess) . ',' .
841 t3lib_div::quoteJSvalue($emailMess) . ')"';
842 $GLOBALS['TSFE']->additionalHeaderData['JSFormValidate'] = '<script type="text/javascript" src="' .
843 t3lib_div::createVersionNumberedFilename($GLOBALS['TSFE']->absRefPrefix .
844 't3lib/jsfunc.validateform.js') . '"></script>';
845 } else {
846 $validateForm = '';
847 }
848
849 // Create form tag:
850 $theTarget = ($theRedirect ? $LD['target'] : $LD_A['target']);
851 $method = isset($conf['method.'])
852 ? $this->cObj->stdWrap($conf['method'], $conf['method.'])
853 : $conf['method'];
854 $content = array(
855 '<form' . ' action="' . htmlspecialchars($action) . '"' . ' id="' .
856 $formName . '"' . ($xhtmlStrict ? '' : ' name="' . $formName . '"') .
857 ' enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '"' .
858 ' method="' . ($method ? $method : 'post') . '"' .
859 ($theTarget ? ' target="' . $theTarget . '"' : '') .
860 $validateForm . '>', $hiddenfields . $content,
861 '</form>'
862 );
863
864 $arrayReturnMode = isset($conf['arrayReturnMode.'])
865 ? $this->cObj->stdWrap($conf['arrayReturnMode'], $conf['arrayReturnMode.'])
866 : $conf['arrayReturnMode'];
867 if ($arrayReturnMode) {
868 $content['validateForm'] = $validateForm;
869 $content['formname'] = $formName;
870 return $content;
871 } else {
872 return implode('', $content);
873 }
874 }
875
876 }
877
878
879 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/content/class.tslib_content_form.php'])) {
880 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/content/class.tslib_content_form.php']);
881 }
882
883 ?>