TYPO3 API  SVNRelease
class.tslib_content_form.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003  *  Copyright notice
00004  *
00005  *  (c) 2010-2011 Xavier Perseguers <typo3@perseguers.ch>
00006  *  (c) 2010-2011 Steffen Kamper <steffen@typo3.org>
00007  *  All rights reserved
00008  *
00009  *  This script is part of the TYPO3 project. The TYPO3 project is
00010  *  free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  The GNU General Public License can be found at
00016  *  http://www.gnu.org/copyleft/gpl.html.
00017  *  A copy is found in the textfile GPL.txt and important notices to the license
00018  *  from the author is found in LICENSE.txt distributed with these scripts.
00019  *
00020  *
00021  *  This script is distributed in the hope that it will be useful,
00022  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00023  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00024  *  GNU General Public License for more details.
00025  *
00026  *  This copyright notice MUST APPEAR in all copies of the script!
00027  ***************************************************************/
00028 
00029 /**
00030  * Contains FORM class object.
00031  *
00032  * $Id: class.tslib_content.php 7905 2010-06-13 14:42:33Z ohader $
00033  * @author Xavier Perseguers <typo3@perseguers.ch>
00034  * @author Steffen Kamper <steffen@typo3.org>
00035  */
00036 class tslib_content_Form extends tslib_content_Abstract {
00037 
00038     /**
00039      * Rendering the cObject, FORM
00040      *
00041      * Note on $formData:
00042      * In the optional $formData array each entry represents a line in the ordinary setup.
00043      * In those entries each entry (0,1,2...) represents a space normally divided by the '|' line.
00044      *
00045      * $formData [] = array('Name:', 'name=input, 25 ', 'Default value....');
00046      * $formData [] = array('Email:', 'email=input, 25 ', 'Default value for email....');
00047      *
00048      * - corresponds to the $conf['data'] value being :
00049      * Name:|name=input, 25 |Default value....||Email:|email=input, 25 |Default value for email....
00050      *
00051      * If $formData is an array the value of $conf['data'] is ignored.
00052      *
00053      * @param   array       Array of TypoScript properties
00054      * @param   array       Alternative formdata overriding whatever comes from TypoScript
00055      * @return  string      Output
00056      */
00057     public function render($conf = array(), $formData = '') {
00058         $content = '';
00059         if (is_array($formData)) {
00060             $dataArray = $formData;
00061         } else {
00062             $data = isset($conf['data.'])
00063                 ? $this->cObj->stdWrap($conf['data'], $conf['data.'])
00064                 : $conf['data'];
00065                 // Clearing dataArr
00066             $dataArray = array();
00067                 // Getting the original config
00068             if (trim($data)) {
00069                 $data = str_replace(LF, '||', $data);
00070                 $dataArray = explode('||', $data);
00071             }
00072                 // Adding the new dataArray config form:
00073             if (is_array($conf['dataArray.'])) { // dataArray is supplied
00074                 $sortedKeyArray = t3lib_TStemplate::sortedKeyList($conf['dataArray.'], TRUE);
00075                 foreach ($sortedKeyArray as $theKey) {
00076                     $singleKeyArray = $conf['dataArray.'][$theKey . '.'];
00077                     if (is_array($singleKeyArray)) {
00078                         $temp = array();
00079                         $label = isset($singleKeyArray['label.'])
00080                             ? $this->cObj->stdWrap($singleKeyArray['label'], $singleKeyArray['label.'])
00081                             : $singleKeyArray['label'];
00082                         list ($temp[0]) = explode('|', $label);
00083                         $type = isset($singleKeyArray['type.'])
00084                             ? $this->cObj->stdWrap($singleKeyArray['type'],$singleKeyArray['type.'])
00085                             : $singleKeyArray['type'];
00086                         list ($temp[1]) = explode('|', $type);
00087                         $required = isset($singleKeyArray['required.'])
00088                             ? $this->cObj->stdWrap($singleKeyArray['required'], $singleKeyArray['required.'])
00089                             : $singleKeyArray['required'];
00090                         if ($required) {
00091                             $temp[1] = '*' . $temp[1];
00092                         }
00093                         $singleValue = isset($singleKeyArray['value.'])
00094                             ? $this->cObj->stdWrap($singleKeyArray['value'], $singleKeyArray['value.'])
00095                             : $singleKeyArray['value'];
00096                         list ($temp[2]) = explode('|', $singleValue);
00097                             // If value array is set, then implode those values.
00098                         if (is_array($singleKeyArray['valueArray.'])) {
00099                             $temp_accumulated = array();
00100                             foreach ($singleKeyArray['valueArray.'] as $singleKey => $singleKey_valueArray) {
00101                                 if (is_array($singleKey_valueArray) && !strcmp(intval($singleKey) . '.', $singleKey)) {
00102                                     $temp_valueArray = array();
00103                                     $valueArrayLabel = isset($singleKey_valueArray['label.'])
00104                                         ? $this->cObj->stdWrap($singleKey_valueArray['label'], $singleKey_valueArray['label.'])
00105                                         : $singleKey_valueArray['label'];
00106                                     list ($temp_valueArray[0]) = explode('=', $valueArrayLabel);
00107                                     $selected = isset($singleKeyArray['selected.'])
00108                                         ? $this->cObj->stdWrap($singleKeyArray['selected'], $singleKeyArray['selected.'])
00109                                         : $singleKeyArray['selected'];
00110                                     if ($selected) {
00111                                         $temp_valueArray[0] = '*' . $temp_valueArray[0];
00112                                     }
00113                                     $singleKeyValue = isset($singleKey_valueArray['value.'])
00114                                         ? $this->cObj->stdWrap($singleKey_valueArray['value'], $singleKey_valueArray['value.'])
00115                                         : $singleKey_valueArray['value'];
00116                                     list ($temp_valueArray[1]) = explode(',', $singleKeyValue);
00117                                 }
00118                                 $temp_accumulated[] = implode('=', $temp_valueArray);
00119                             }
00120                             $temp[2] = implode(',', $temp_accumulated);
00121                         }
00122                         $specialEval = isset($singleKeyArray['specialEval.'])
00123                             ? $this->cObj->stdWrap($singleKeyArray['specialEval'], $singleKeyArray['specialEval.'])
00124                             : $singleKeyArray['specialEval'];
00125                         list ($temp[3]) = explode('|', $specialEval);
00126 
00127                             // adding the form entry to the dataArray
00128                         $dataArray[] = implode('|', $temp);
00129                     }
00130                 }
00131             }
00132         }
00133 
00134         $attachmentCounter = '';
00135         $hiddenfields = '';
00136         $fieldlist = array();
00137         $propertyOverride = array();
00138         $fieldname_hashArray = array();
00139         $counter = 0;
00140 
00141         $xhtmlStrict = t3lib_div::inList('xhtml_strict,xhtml_11,xhtml_2', $GLOBALS['TSFE']->xhtmlDoctype);
00142             // Formname
00143         $formName = isset($conf['formName.'])
00144             ? $this->cObj->stdWrap($conf['formName'], $conf['formName.'])
00145             : $conf['formName'];
00146         if ($formName) {
00147             $formName = $this->cObj->cleanFormName($formName);
00148         } else {
00149             $formName = 'a' . $GLOBALS['TSFE']->uniqueHash(); // form name has to start with a letter to reach XHTML compliance
00150         }
00151 
00152         $fieldPrefix = isset($conf['fieldPrefix.'])
00153             ? $this->cObj->stdWrap($conf['fieldPrefix'], $conf['fieldPrefix.'])
00154             : $conf['fieldPrefix'];
00155         if (isset($conf['fieldPrefix']) || isset($conf['fieldPrefix.'])) {
00156             if ($fieldPrefix) {
00157                 $prefix = $this->cObj->cleanFormName($fieldPrefix);
00158             } else {
00159                 $prefix = '';
00160             }
00161         } else {
00162             $prefix = $formName;
00163         }
00164 
00165         foreach ($dataArray as $dataValue) {
00166 
00167             $counter++;
00168             $confData = array();
00169             if (is_array($formData)) {
00170                 $parts = $dataValue;
00171                 $dataValue = 1; // TRUE...
00172             } else {
00173                 $dataValue = trim($dataValue);
00174                 $parts = explode('|', $dataValue);
00175             }
00176             if ($dataValue && strcspn($dataValue, '#/')) {
00177                     // label:
00178                 $confData['label'] = t3lib_div::removeXSS(trim($parts[0]));
00179                     // field:
00180                 $fParts = explode(',', $parts[1]);
00181                 $fParts[0] = trim($fParts[0]);
00182                 if (substr($fParts[0], 0, 1) == '*') {
00183                     $confData['required'] = 1;
00184                     $fParts[0] = substr($fParts[0], 1);
00185                 }
00186                 $typeParts = explode('=', $fParts[0]);
00187                 $confData['type'] = trim(strtolower(end($typeParts)));
00188                 if (count($typeParts) == 1) {
00189                     $confData['fieldname'] = $this->cObj->cleanFormName($parts[0]);
00190                     if (strtolower(preg_replace('/[^[:alnum:]]/', '', $confData['fieldname'])) == 'email') {
00191                         $confData['fieldname'] = 'email';
00192                     }
00193                         // Duplicate fieldnames resolved
00194                     if (isset($fieldname_hashArray[md5($confData['fieldname'])])) {
00195                         $confData['fieldname'] .= '_' . $counter;
00196                     }
00197                     $fieldname_hashArray[md5($confData['fieldname'])] = $confData['fieldname'];
00198                         // Attachment names...
00199                     if ($confData['type'] == 'file') {
00200                         $confData['fieldname'] = 'attachment' . $attachmentCounter;
00201                         $attachmentCounter = intval($attachmentCounter) + 1;
00202                     }
00203                 } else {
00204                     $confData['fieldname'] = str_replace(' ', '_', trim($typeParts[0]));
00205                 }
00206                 $confData['fieldname'] = htmlspecialchars($confData['fieldname']);
00207                 $fieldCode = '';
00208 
00209                 $wrapFieldName = isset($conf['wrapFieldName'])
00210                     ? $this->cObj->stdWrap($conf['wrapFieldName'], $conf['wrapFieldName.'])
00211                     : $conf['wrapFieldName'];
00212                 if ($wrapFieldName) {
00213                     $confData['fieldname'] = $this->cObj->wrap($confData['fieldname'], $wrapFieldName);
00214                 }
00215 
00216                     // Set field name as current:
00217                 $this->cObj->setCurrentVal($confData['fieldname']);
00218 
00219                     // Additional parameters
00220                 if (trim($confData['type'])) {
00221                     if (isset($conf['params.'][$confData['type']])) {
00222                         $addParams = isset($conf['params.'][$confData['type'] . '.'])
00223                             ? trim($this->cObj->stdWrap($conf['params.'][$confData['type']], $conf['params.'][$confData['type'] . '.']))
00224                             : trim($conf['params.'][$confData['type']]);
00225                     } else {
00226                         $addParams = isset($conf['params.'])
00227                             ? trim($this->cObj->stdWrap($conf['params'], $conf['params.']))
00228                             : trim($conf['params']);
00229                     }
00230                     if (strcmp('', $addParams)) {
00231                         $addParams = ' ' . $addParams;
00232                     }
00233                 } else
00234                     $addParams = '';
00235 
00236                 $dontMd5FieldNames = isset($conf['dontMd5FieldNames.'])
00237                     ? $this->cObj->stdWrap($conf['dontMd5FieldNames'], $conf['dontMd5FieldNames.'])
00238                     : $conf['dontMd5FieldNames'];
00239                 if ($dontMd5FieldNames) {
00240                     $fName = $confData['fieldname'];
00241                 } else {
00242                     $fName = md5($confData['fieldname']);
00243                 }
00244 
00245                     // Accessibility: Set id = fieldname attribute:
00246                 $accessibility = isset($conf['accessibility.'])
00247                     ? $this->cObj->stdWrap($conf['accessibility'], $conf['accessibility.'])
00248                     : $conf['accessibility'];
00249                 if ($accessibility || $xhtmlStrict) {
00250                     $elementIdAttribute = ' id="' . $prefix . $fName . '"';
00251                 } else {
00252                     $elementIdAttribute = '';
00253                 }
00254 
00255                     // Create form field based on configuration/type:
00256                 switch ($confData['type']) {
00257                     case 'textarea' :
00258                         $cols = trim($fParts[1]) ? intval($fParts[1]) : 20;
00259                         $compensateFieldWidth = isset($conf['compensateFieldWidth.'])
00260                             ? $this->cObj->stdWrap($conf['compensateFieldWidth'], $conf['compensateFieldWidth.'])
00261                             : $conf['compensateFieldWidth'];
00262                         $compWidth = doubleval($compensateFieldWidth
00263                                         ? $compensateFieldWidth
00264                                         : $GLOBALS['TSFE']->compensateFieldWidth
00265                                     );
00266                         $compWidth = $compWidth ? $compWidth : 1;
00267                         $cols = t3lib_div::intInRange($cols * $compWidth, 1, 120);
00268 
00269                         $rows = trim($fParts[2]) ? t3lib_div::intInRange($fParts[2], 1, 30) : 5;
00270                         $wrap = trim($fParts[3]);
00271                         $noWrapAttr = isset($conf['noWrapAttr.'])
00272                             ? $this->cObj->stdWrap($conf['noWrapAttr'], $conf['noWrapAttr.'])
00273                             : $conf['noWrapAttr'];
00274                         if ($noWrapAttr || $wrap === 'disabled') {
00275                             $wrap = '';
00276                         } else {
00277                             $wrap = $wrap ? ' wrap="' . $wrap . '"' : ' wrap="virtual"';
00278                         }
00279                         $noValueInsert = isset($conf['noValueInsert.'])
00280                             ? $this->cObj->stdWrap($conf['noValueInsert'], $conf['noValueInsert.'])
00281                             : $conf['noValueInsert'];
00282                         $default = $this->cObj->getFieldDefaultValue(
00283                             $noValueInsert,
00284                             $confData['fieldname'],
00285                             str_replace('\n', LF, trim($parts[2]))
00286                         );
00287                         $fieldCode = sprintf(
00288                             '<textarea name="%s"%s cols="%s" rows="%s"%s%s>%s</textarea>',
00289                             $confData['fieldname'],
00290                             $elementIdAttribute,
00291                             $cols,
00292                             $rows,
00293                             $wrap,
00294                             $addParams,
00295                             t3lib_div::formatForTextarea($default)
00296                         );
00297                     break;
00298                     case 'input' :
00299                     case 'password' :
00300                         $size = trim($fParts[1]) ? intval($fParts[1]) : 20;
00301                         $compensateFieldWidth = isset($conf['compensateFieldWidth.'])
00302                             ? $this->cObj->stdWrap($conf['compensateFieldWidth'], $conf['compensateFieldWidth.'])
00303                             : $conf['compensateFieldWidth'];
00304                         $compWidth = doubleval($compensateFieldWidth
00305                                         ? $compensateFieldWidth
00306                                         : $GLOBALS['TSFE']->compensateFieldWidth
00307                                     );
00308                         $compWidth = $compWidth ? $compWidth : 1;
00309                         $size = t3lib_div::intInRange($size * $compWidth, 1, 120);
00310                         $noValueInsert = isset($conf['noValueInsert.'])
00311                             ? $this->cObj->stdWrap($conf['noValueInsert'], $conf['noValueInsert.'])
00312                             : $conf['noValueInsert'];
00313                         $default = $this->cObj->getFieldDefaultValue(
00314                             $noValueInsert,
00315                             $confData['fieldname'],
00316                             trim($parts[2])
00317                         );
00318 
00319                         if ($confData['type'] == 'password') {
00320                             $default = '';
00321                         }
00322 
00323                         $max = trim($fParts[2]) ? ' maxlength="' . t3lib_div::intInRange($fParts[2], 1, 1000) . '"' : "";
00324                         $theType = $confData['type'] == 'input' ? 'text' : 'password';
00325 
00326                         $fieldCode = sprintf(
00327                             '<input type="%s" name="%s"%s size="%s"%s value="%s"%s />',
00328                             $theType,
00329                             $confData['fieldname'],
00330                             $elementIdAttribute,
00331                             $size,
00332                             $max,
00333                             htmlspecialchars($default),
00334                             $addParams
00335                         );
00336 
00337                     break;
00338                     case 'file' :
00339                         $size = trim($fParts[1]) ? t3lib_div::intInRange($fParts[1], 1, 60) : 20;
00340                         $fieldCode = sprintf(
00341                             '<input type="file" name="%s"%s size="%s"%s />',
00342                             $confData['fieldname'],
00343                             $elementIdAttribute,
00344                             $size,
00345                             $addParams
00346                         );
00347                     break;
00348                     case 'check' :
00349                             // alternative default value:
00350                         $noValueInsert = isset($conf['noValueInsert.'])
00351                             ? $this->cObj->stdWrap($conf['noValueInsert'], $conf['noValueInsert.'])
00352                             : $conf['noValueInsert'];
00353                         $default = $this->cObj->getFieldDefaultValue(
00354                             $noValueInsert,
00355                             $confData['fieldname'],
00356                             trim($parts[2])
00357                         );
00358                         $checked = $default ? ' checked="checked"' : '';
00359                         $fieldCode = sprintf(
00360                             '<input type="checkbox" value="%s" name="%s"%s%s%s />',
00361                             1,
00362                             $confData['fieldname'],
00363                             $elementIdAttribute,
00364                             $checked,
00365                             $addParams
00366                         );
00367                     break;
00368                     case 'select' :
00369                         $option = '';
00370                         $valueParts = explode(',', $parts[2]);
00371                             // size
00372                         if (strtolower(trim($fParts[1])) == 'auto') {
00373                             $fParts[1] = count($valueParts);
00374                         } // Auto size set here. Max 20
00375                         $size = trim($fParts[1]) ? t3lib_div::intInRange($fParts[1], 1, 20) : 1;
00376                             // multiple
00377                         $multiple = strtolower(trim($fParts[2])) == 'm' ? ' multiple="multiple"' : '';
00378 
00379                         $items = array(); // Where the items will be
00380                         $defaults = array(); //RTF
00381                         $pCount = count($valueParts);
00382                         for ($a = 0; $a < $pCount; $a++) {
00383                             $valueParts[$a] = trim($valueParts[$a]);
00384                             if (substr($valueParts[$a], 0, 1) == '*') { // Finding default value
00385                                 $sel = 'selected';
00386                                 $valueParts[$a] = substr($valueParts[$a], 1);
00387                             } else
00388                                 $sel = '';
00389                                 // Get value/label
00390                             $subParts = explode('=', $valueParts[$a]);
00391                             $subParts[1] = (isset($subParts[1]) ? trim($subParts[1]) : trim($subParts[0])); // Sets the value
00392                             $items[] = $subParts; // Adds the value/label pair to the items-array
00393                             if ($sel) {
00394                                 $defaults[] = $subParts[1];
00395                             } // Sets the default value if value/label pair is marked as default.
00396                         }
00397                             // alternative default value:
00398                         $noValueInsert = isset($conf['noValueInsert.'])
00399                             ? $this->cObj->stdWrap($conf['noValueInsert'], $conf['noValueInsert.'])
00400                             : $conf['noValueInsert'];
00401                         $default = $this->cObj->getFieldDefaultValue(
00402                             $noValueInsert,
00403                             $confData['fieldname'],
00404                             $defaults
00405                         );
00406                         if (!is_array($default)) {
00407                             $defaults = array();
00408                             $defaults[] = $default;
00409                         } else {
00410                             $defaults = $default;
00411                         }
00412                             // Create the select-box:
00413                         $iCount = count($items);
00414                         for ($a = 0; $a < $iCount; $a++) {
00415                             $option .= '<option value="' . $items[$a][1] . '"' . (in_array($items[$a][1], $defaults) ? ' selected="selected"' : '') . '>' . trim($items[$a][0]) . '</option>'; //RTF
00416                         }
00417 
00418                         if ($multiple) {
00419                                 // 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.
00420                             $confData['fieldname'] .= '[]';
00421                         }
00422                         $fieldCode = sprintf(
00423                             '<select name="%s"%s size="%s"%s%s>%s</select>',
00424                             $confData['fieldname'],
00425                             $elementIdAttribute,
00426                             $size,
00427                             $multiple,
00428                             $addParams,
00429                             $option
00430                         ); //RTF
00431                     break;
00432                     case 'radio' :
00433                         $option = '';
00434 
00435                         $valueParts = explode(',', $parts[2]);
00436                         $items = array(); // Where the items will be
00437                         $default = '';
00438                         $pCount = count($valueParts);
00439                         for ($a = 0; $a < $pCount; $a++) {
00440                             $valueParts[$a] = trim($valueParts[$a]);
00441                             if (substr($valueParts[$a], 0, 1) == '*') {
00442                                 $sel = 'checked';
00443                                 $valueParts[$a] = substr($valueParts[$a], 1);
00444                             } else
00445                                 $sel = '';
00446                                 // Get value/label
00447                             $subParts = explode('=', $valueParts[$a]);
00448                             $subParts[1] = (isset($subParts[1]) ? trim($subParts[1]) : trim($subParts[0])); // Sets the value
00449                             $items[] = $subParts; // Adds the value/label pair to the items-array
00450                             if ($sel) {
00451                                 $default = $subParts[1];
00452                             } // Sets the default value if value/label pair is marked as default.
00453                         }
00454                             // alternative default value:
00455                         $noValueInsert = isset($conf['noValueInsert.'])
00456                             ? $this->cObj->stdWrap($conf['noValueInsert'], $conf['noValueInsert.'])
00457                             : $conf['noValueInsert'];
00458                         $default = $this->cObj->getFieldDefaultValue(
00459                             $noValueInsert,
00460                             $confData['fieldname'],
00461                             $default
00462                         );
00463                             // Create the select-box:
00464                         $iCount = count($items);
00465                         for ($a = 0; $a < $iCount; $a++) {
00466                             $optionParts = '';
00467                             $radioId = $prefix . $fName . $this->cObj->cleanFormName($items[$a][0]);
00468                             if ($accessibility) {
00469                                 $radioLabelIdAttribute = ' id="' . $radioId . '"';
00470                             } else {
00471                                 $radioLabelIdAttribute = '';
00472                             }
00473                             $optionParts .= '<input type="radio" name="' . $confData['fieldname'] . '"' .
00474                                     $radioLabelIdAttribute . ' value="' . $items[$a][1] . '"' .
00475                                     (!strcmp($items[$a][1], $default) ? ' checked="checked"' : '') . $addParams . ' />';
00476                             if ($accessibility) {
00477                                 $label = isset($conf['radioWrap.'])
00478                                     ? $this->cObj->stdWrap(trim($items[$a][0]), $conf['radioWrap.'])
00479                                     : trim($items[$a][0]);
00480                                 $optionParts .= '<label for="' . $radioId . '">' . $label  . '</label>';
00481                             } else {
00482                                 $optionParts .= isset($conf['radioWrap.'])
00483                                     ? $this->cObj->stdWrap(trim($items[$a][0]), $conf['radioWrap.'])
00484                                     : trim($items[$a][0]);
00485                             }
00486                             $option .= isset($conf['radioInputWrap.'])
00487                                 ? $this->cObj->stdWrap($optionParts, $conf['radioInputWrap.'])
00488                                 : $optionParts;
00489                         }
00490 
00491                         if ($accessibility) {
00492                             $accessibilityWrap = isset($conf['radioWrap.']['accessibilityWrap.'])
00493                                 ? $this->cObj->stdWrap($conf['radioWrap.']['accessibilityWrap'], $conf['radioWrap.']['accessibilityWrap.'])
00494                                 : $conf['radioWrap.']['accessibilityWrap.'];
00495 
00496                             if($accessibilityWrap) {
00497                                 $search = array(
00498                                     '###RADIO_FIELD_ID###', '###RADIO_GROUP_LABEL###'
00499                                 );
00500                                 $replace = array(
00501                                     $elementIdAttribute, $confData['label']
00502                                 );
00503                                 $accessibilityWrap = str_replace($search, $replace, $accessibilityWrap);
00504 
00505                                 $option = $this->cObj->wrap($option, $accessibilityWrap);
00506                             }
00507                         }
00508 
00509                         $fieldCode = $option;
00510                     break;
00511                     case 'hidden' :
00512                         $value = trim($parts[2]);
00513 
00514                             // If this form includes an auto responder message, include a HMAC checksum field
00515                             // in order to verify potential abuse of this feature.
00516                         if (strlen($value) && t3lib_div::inList($confData['fieldname'], 'auto_respond_msg')) {
00517                             $hmacChecksum = t3lib_div::hmac($value);
00518                             $hiddenfields .= sprintf(
00519                                 '<input type="hidden" name="auto_respond_checksum" id="%sauto_respond_checksum" value="%s" />',
00520                                 $prefix,
00521                                 $hmacChecksum
00522                             );
00523                         }
00524 
00525                         if (strlen($value) && t3lib_div::inList('recipient_copy,recipient',
00526                             $confData['fieldname']) && $GLOBALS['TYPO3_CONF_VARS']['FE']['secureFormmail']) {
00527                             break;
00528                         }
00529                         if (strlen($value) && t3lib_div::inList('recipient_copy,recipient', $confData['fieldname'])) {
00530                             $value = $GLOBALS['TSFE']->codeString($value);
00531                         }
00532                         $hiddenfields .= sprintf(
00533                             '<input type="hidden" name="%s"%s value="%s" />',
00534                             $confData['fieldname'],
00535                             $elementIdAttribute,
00536                             htmlspecialchars($value)
00537                         );
00538                     break;
00539                     case 'property' :
00540                         if (t3lib_div::inList('type,locationData,goodMess,badMess,emailMess', $confData['fieldname'])) {
00541                             $value = trim($parts[2]);
00542                             $propertyOverride[$confData['fieldname']] = $value;
00543                             $conf[$confData['fieldname']] = $value;
00544                         }
00545                     break;
00546                     case 'submit' :
00547                         $value = trim($parts[2]);
00548                         if ($conf['image.']) {
00549                             $this->cObj->data[$this->cObj->currentValKey] = $value;
00550                             $image = $this->cObj->IMG_RESOURCE($conf['image.']);
00551                             $params = $conf['image.']['params'] ? ' ' . $conf['image.']['params'] : '';
00552                             $params .= $this->cObj->getAltParam($conf['image.'], FALSE);
00553                             $params .= $addParams;
00554                         } else {
00555                             $image = '';
00556                         }
00557                         if ($image) {
00558                             $fieldCode = sprintf(
00559                                 '<input type="image" name="%s"%s src="%s"%s />',
00560                                 $confData['fieldname'],
00561                                 $elementIdAttribute,
00562                                 $image,
00563                                 $params
00564                             );
00565                         } else {
00566                             $fieldCode = sprintf(
00567                                 '<input type="submit" name="%s"%s value="%s"%s />',
00568                                 $confData['fieldname'],
00569                                 $elementIdAttribute,
00570                                 t3lib_div::deHSCentities(htmlspecialchars($value)),
00571                                 $addParams
00572                             );
00573                         }
00574                     break;
00575                     case 'reset' :
00576                         $value = trim($parts[2]);
00577                         $fieldCode = sprintf(
00578                             '<input type="reset" name="%s"%s value="%s"%s />',
00579                             $confData['fieldname'],
00580                             $elementIdAttribute,
00581                             t3lib_div::deHSCentities(htmlspecialchars($value)),
00582                             $addParams
00583                         );
00584                     break;
00585                     case 'label' :
00586                         $fieldCode = nl2br(htmlspecialchars(trim($parts[2])));
00587                     break;
00588                     default :
00589                         $confData['type'] = 'comment';
00590                         $fieldCode = trim($parts[2]) . '&nbsp;';
00591                     break;
00592                 }
00593                 if ($fieldCode) {
00594 
00595                         // Checking for special evaluation modes:
00596                     if (t3lib_div::inList('textarea,input,password', $confData['type']) && strlen(trim($parts[3]))) {
00597                         $modeParameters = t3lib_div::trimExplode(':', $parts[3]);
00598                     } else {
00599                         $modeParameters = array();
00600                     }
00601 
00602                     // Adding evaluation based on settings:
00603                     switch ((string) $modeParameters[0]) {
00604                         case 'EREG' :
00605                             $fieldlist[] = '_EREG';
00606                             $fieldlist[] = $modeParameters[1];
00607                             $fieldlist[] = $modeParameters[2];
00608                             $fieldlist[] = $confData['fieldname'];
00609                             $fieldlist[] = $confData['label'];
00610                             $confData['required'] = 1; // Setting this so "required" layout is used.
00611                         break;
00612                         case 'EMAIL' :
00613                             $fieldlist[] = '_EMAIL';
00614                             $fieldlist[] = $confData['fieldname'];
00615                             $fieldlist[] = $confData['label'];
00616                             $confData['required'] = 1; // Setting this so "required" layout is used.
00617                         break;
00618                         default :
00619                             if ($confData['required']) {
00620                                 $fieldlist[] = $confData['fieldname'];
00621                                 $fieldlist[] = $confData['label'];
00622                             }
00623                         break;
00624                     }
00625 
00626                         // Field:
00627                     $fieldLabel = $confData['label'];
00628                     if ($accessibility && trim($fieldLabel) && !preg_match('/^(label|hidden|comment)$/', $confData['type'])) {
00629                         $fieldLabel = '<label for="' . $prefix . $fName . '">' . $fieldLabel . '</label>';
00630                     }
00631 
00632                         // Getting template code:
00633                     if(isset($conf['fieldWrap.'])) {
00634                         $fieldCode = $this->cObj->stdWrap($fieldCode, $conf['fieldWrap.']);
00635                     }
00636                     $labelCode = isset($conf['labelWrap.'])
00637                         ? $this->cObj->stdWrap($fieldLabel, $conf['labelWrap.'])
00638                         : $fieldLabel;
00639                     $commentCode = isset($conf['commentWrap.'])
00640                         ? $this->cObj->stdWrap($confData['label'], $conf['commentWrap.']) // RTF
00641                         : $confData['label'];
00642                     $result = $conf['layout'];
00643                     $req = isset($conf['REQ.'])
00644                         ? $this->cObj->stdWrap($conf['REQ'], $conf['REQ.'])
00645                         : $conf['REQ'];
00646                     if ($req && $confData['required']) {
00647                         if (isset($conf['REQ.']['fieldWrap.'])) {
00648                             $fieldCode = $this->cObj->stdWrap($fieldCode, $conf['REQ.']['fieldWrap.']);
00649                         }
00650                         if (isset($conf['REQ.']['labelWrap.'])) {
00651                             $labelCode = $this->cObj->stdWrap($fieldLabel, $conf['REQ.']['labelWrap.']);
00652                         }
00653                         $reqLayout = isset($conf['REQ.']['layout.'])
00654                             ? $this->cObj->stdWrap($conf['REQ.']['layout'], $conf['REQ.']['layout.'])
00655                             : $conf['REQ.']['layout'];
00656                         if ($reqLayout) {
00657                             $result = $reqLayout;
00658                         }
00659                     }
00660                     if ($confData['type'] == 'comment') {
00661                         $commentLayout = isset($conf['COMMENT.']['layout.'])
00662                             ? $this->cObj->stdWrap($conf['COMMENT.']['layout'], $conf['COMMENT.']['layout.'])
00663                             : $conf['COMMENT.']['layout'];
00664                         if ($commentLayout) {
00665                             $result = $commentLayout;
00666                         }
00667                     }
00668                     if ($confData['type'] == 'check') {
00669                         $checkLayout = isset($conf['CHECK.']['layout.'])
00670                             ? $this->cObj->stdWrap($conf['CHECK.']['layout'], $conf['CHECK.']['layout.'])
00671                             : $conf['CHECK.']['layout'];
00672                         if ($checkLayout) {
00673                             $result = $checkLayout;
00674                         }
00675                     }
00676                     if ($confData['type'] == 'radio') {
00677                         $radioLayout = isset($conf['RADIO.']['layout.'])
00678                             ? $this->cObj->stdWrap($conf['RADIO.']['layout'], $conf['RADIO.']['layout.'])
00679                             : $conf['RADIO.']['layout'];
00680                         if ($radioLayout) {
00681                             $result = $radioLayout;
00682                         }
00683                     }
00684                     if ($confData['type'] == 'label') {
00685                         $labelLayout = isset($conf['LABEL.']['layout.'])
00686                             ? $this->cObj->stdWrap($conf['LABEL.']['layout'], $conf['LABEL.']['layout.'])
00687                             : $conf['CHECK.']['layout'];
00688                         if ($labelLayout) {
00689                             $result = $labelLayout;
00690                         }
00691                     }
00692                     $result = str_replace('###FIELD###', $fieldCode, $result);
00693                     $result = str_replace('###LABEL###', $labelCode, $result);
00694                     $result = str_replace('###COMMENT###', $commentCode, $result); //RTF
00695                     $content .= $result;
00696                 }
00697             }
00698         }
00699         if (isset($conf['stdWrap.'])) {
00700             $content = $this->cObj->stdWrap($content, $conf['stdWrap.']);
00701         }
00702 
00703 
00704             // redirect (external: where to go afterwards. internal: where to submit to)
00705         $theRedirect = isset($conf['redirect.'])
00706             ? $this->cObj->stdWrap($conf['redirect'], $conf['redirect.'])
00707             : $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)
00708         $target = isset($conf['target.'])
00709             ? $this->cObj->stdWrap($conf['target'], $conf['target.'])
00710             : $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)
00711         $noCache = isset($conf['no_cache.'])
00712             ? $this->cObj->stdWrap($conf['no_cache'], $conf['no_cache.'])
00713             : $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)
00714         $page = $GLOBALS['TSFE']->page;
00715         if (!$theRedirect) { // Internal: Just submit to current page
00716             $LD = $GLOBALS['TSFE']->tmpl->linkData(
00717                 $page,
00718                 $target,
00719                 $noCache,
00720                 'index.php',
00721                 '',
00722                 $this->cObj->getClosestMPvalueForPage($page['uid'])
00723             );
00724         } elseif (t3lib_div::testInt($theRedirect)) { // Internal: Submit to page with ID $theRedirect
00725             $page = $GLOBALS['TSFE']->sys_page->getPage_noCheck($theRedirect);
00726             $LD = $GLOBALS['TSFE']->tmpl->linkData(
00727                 $page,
00728                 $target,
00729                 $noCache,
00730                 'index.php',
00731                 '',
00732                 $this->cObj->getClosestMPvalueForPage($page['uid'])
00733             );
00734         } else { // External URL, redirect-hidden field is rendered!
00735             $LD = $GLOBALS['TSFE']->tmpl->linkData(
00736                 $page,
00737                 $target,
00738                 $noCache,
00739                 '',
00740                 '',
00741                 $this->cObj->getClosestMPvalueForPage($page['uid'])
00742             );
00743             $LD['totalURL'] = $theRedirect;
00744             $hiddenfields .= '<input type="hidden" name="redirect" value="' . htmlspecialchars($LD['totalURL']) . '" />'; // 18-09-00 added
00745         }
00746 
00747             // Formtype (where to submit to!):
00748         if($propertyOverride['type']) {
00749             $formtype = $propertyOverride['type'];
00750         } else {
00751             $formtype = isset($conf['type.'])
00752                 ? $this->cObj->stdWrap($conf['type'], $conf['type.'])
00753                 : $conf['type'];
00754         }
00755         if (t3lib_div::testInt($formtype)) { // Submit to a specific page
00756             $page = $GLOBALS['TSFE']->sys_page->getPage_noCheck($formtype);
00757             $LD_A = $GLOBALS['TSFE']->tmpl->linkData(
00758                 $page,
00759                 $target,
00760                 $noCache,
00761                 '',
00762                 '',
00763                 $this->cObj->getClosestMPvalueForPage($page['uid'])
00764             );
00765             $action = $LD_A['totalURL'];
00766         } elseif ($formtype) { // Submit to external script
00767             $LD_A = $LD;
00768             $action = $formtype;
00769         } elseif (t3lib_div::testInt($theRedirect)) {
00770             $LD_A = $LD;
00771             $action = $LD_A['totalURL'];
00772         } else { // Submit to "nothing" - which is current page
00773             $LD_A = $GLOBALS['TSFE']->tmpl->linkData(
00774                 $GLOBALS['TSFE']->page,
00775                 $target,
00776                 $noCache,
00777                 '',
00778                 '',
00779                 $this->cObj->getClosestMPvalueForPage($page['uid'])
00780             );
00781             $action = $LD_A['totalURL'];
00782         }
00783 
00784             // Recipient:
00785         $theEmail = isset($conf['recipient.'])
00786             ? $this->cObj->stdWrap($conf['recipient'], $conf['recipient.'])
00787             : $conf['recipient'];
00788         if ($theEmail && !$GLOBALS['TYPO3_CONF_VARS']['FE']['secureFormmail']) {
00789             $theEmail = $GLOBALS['TSFE']->codeString($theEmail);
00790             $hiddenfields .= '<input type="hidden" name="recipient" value="' . htmlspecialchars($theEmail) . '" />';
00791         }
00792 
00793             // location data:
00794         $location = isset($conf['locationData.'])
00795             ? $this->cObj->stdWrap($conf['locationData'], $conf['locationData.'])
00796             : $conf['locationData'];
00797         if ($location) {
00798             if ($location == 'HTTP_POST_VARS' && isset($_POST['locationData'])) {
00799                 $locationData = t3lib_div::_POST('locationData');
00800             } else {
00801                     // 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.
00802                 $locationData = $GLOBALS['TSFE']->id . ':' . $this->cObj->currentRecord;
00803             }
00804             $hiddenfields .= '<input type="hidden" name="locationData" value="' . htmlspecialchars($locationData) . '" />';
00805         }
00806 
00807             // hidden fields:
00808         if (is_array($conf['hiddenFields.'])) {
00809             foreach ($conf['hiddenFields.'] as $hF_key => $hF_conf) {
00810                 if (substr($hF_key, -1) != '.') {
00811                     $hF_value = $this->cObj->cObjGetSingle($hF_conf, $conf['hiddenFields.'][$hF_key . '.'], 'hiddenfields');
00812                     if (strlen($hF_value) && t3lib_div::inList('recipient_copy,recipient', $hF_key)) {
00813                         if ($GLOBALS['TYPO3_CONF_VARS']['FE']['secureFormmail']) {
00814                             continue;
00815                         }
00816                         $hF_value = $GLOBALS['TSFE']->codeString($hF_value);
00817                     }
00818                     $hiddenfields .= '<input type="hidden" name="' . $hF_key . '" value="' . htmlspecialchars($hF_value) . '" />';
00819                 }
00820             }
00821         }
00822 
00823             // Wrap all hidden fields in a div tag (see http://bugs.typo3.org/view.php?id=678)
00824         $hiddenfields = isset($conf['hiddenFields.']['stdWrap.'])
00825             ? $this->cObj->stdWrap($hiddenfields, $conf['hiddenFields.']['stdWrap.'])
00826             : '<div style="display:none;">' . $hiddenfields . '</div>';
00827 
00828         if ($conf['REQ']) {
00829             $goodMess = isset($conf['goodMess.'])
00830                 ? $this->cObj->stdWrap($conf['goodMess'], $conf['goodMess.'])
00831                 : $conf['goodMess'];
00832             $badMess = isset($conf['badMess.'])
00833                 ? $this->cObj->stdWrap($conf['badMess'], $conf['badMess.'])
00834                 : $conf['badMess'];
00835             $emailMess = isset($conf['emailMess.'])
00836                 ? $this->cObj->stdWrap($conf['emailMess'], $conf['emailMess.'])
00837                 : $conf['emailMess'];
00838             $validateForm = ' onsubmit="return validateForm(\'' . $formName . '\',\'' . implode(',', $fieldlist)
00839                 . '\',' . t3lib_div::quoteJSvalue($goodMess) . ',' .
00840                 t3lib_div::quoteJSvalue($badMess) . ',' .
00841                 t3lib_div::quoteJSvalue($emailMess) . ')"';
00842             $GLOBALS['TSFE']->additionalHeaderData['JSFormValidate'] = '<script type="text/javascript" src="' .
00843                 t3lib_div::createVersionNumberedFilename($GLOBALS['TSFE']->absRefPrefix .
00844                 't3lib/jsfunc.validateform.js') . '"></script>';
00845         } else {
00846             $validateForm = '';
00847         }
00848 
00849             // Create form tag:
00850         $theTarget = ($theRedirect ? $LD['target'] : $LD_A['target']);
00851         $method = isset($conf['method.'])
00852             ? $this->cObj->stdWrap($conf['method'], $conf['method.'])
00853             : $conf['method'];
00854         $content = array(
00855             '<form' . ' action="' . htmlspecialchars($action) . '"' . ' id="' .
00856             $formName . '"' . ($xhtmlStrict ? '' : ' name="' . $formName . '"') .
00857             ' enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '"' .
00858             ' method="' . ($method ? $method : 'post') . '"' .
00859             ($theTarget ? ' target="' . $theTarget . '"' : '') .
00860             $validateForm . '>', $hiddenfields . $content,
00861             '</form>'
00862         );
00863 
00864         $arrayReturnMode = isset($conf['arrayReturnMode.'])
00865             ? $this->cObj->stdWrap($conf['arrayReturnMode'], $conf['arrayReturnMode.'])
00866             : $conf['arrayReturnMode'];
00867         if ($arrayReturnMode) {
00868             $content['validateForm'] = $validateForm;
00869             $content['formname'] = $formName;
00870             return $content;
00871         } else {
00872             return implode('', $content);
00873         }
00874     }
00875 
00876 }
00877 
00878 
00879 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/content/class.tslib_content_form.php'])) {
00880     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/content/class.tslib_content_form.php']);
00881 }
00882 
00883 ?>