public function getFormFields(DataContainer $dc) { $arrOptions = array('column' => array("type='stores'")); $objFields = FormFieldModel::findPublishedByPid($dc->id, $arrOptions); if ($objFields) { while ($objFields->next()) { $arrFields[$objFields->name] = $objFields->label; } return $arrFields; } }
/** * Prepare a set of fields. * * @param \FormFieldModel[] $fields The given set of fields being prepared. * @param \FormFieldModel[] $combinedFields The prepared list of form fields. * @param array $formStack A stack of form ids to protect against recursion. * * @return void */ private function prepareFields($fields, &$combinedFields, $formStack) { foreach ($fields as $field) { if ($field->type === 'subform') { $subformFields = \FormFieldModel::findPublishedByPid($field->subform); if ($subformFields && !in_array($field->subform, $formStack)) { $newStack = $formStack; $newStack[] = $field->subform; $this->prepareFields($subformFields, $combinedFields, $newStack); } continue; } $combinedFields[] = $field; } }
/** * Generate the form * * @return string */ protected function compile() { $hasUpload = false; $doNotSubmit = false; $arrSubmitted = array(); $this->loadDataContainer('tl_form_field'); $formId = $this->formID != '' ? 'auto_' . $this->formID : 'auto_form_' . $this->id; $this->Template->fields = ''; $this->Template->hidden = ''; $this->Template->formSubmit = $formId; $this->Template->method = $this->method == 'GET' ? 'get' : 'post'; $this->initializeSession($formId); $arrLabels = array(); // Get all form fields $arrFields = array(); $objFields = \FormFieldModel::findPublishedByPid($this->id); if ($objFields !== null) { while ($objFields->next()) { if ($objFields->name != '') { $arrFields[$objFields->name] = $objFields->current(); } else { $arrFields[] = $objFields->current(); } } } // HOOK: compile form fields if (isset($GLOBALS['TL_HOOKS']['compileFormFields']) && is_array($GLOBALS['TL_HOOKS']['compileFormFields'])) { foreach ($GLOBALS['TL_HOOKS']['compileFormFields'] as $callback) { $this->import($callback[0]); $arrFields = $this->{$callback}[0]->{$callback}[1]($arrFields, $formId, $this); } } // Process the fields if (!empty($arrFields) && is_array($arrFields)) { $row = 0; $max_row = count($arrFields); foreach ($arrFields as $objField) { /** @var \FormFieldModel $objField */ $strClass = $GLOBALS['TL_FFL'][$objField->type]; // Continue if the class is not defined if (!class_exists($strClass)) { continue; } $arrData = $objField->row(); $arrData['decodeEntities'] = true; $arrData['allowHtml'] = $this->allowTags; $arrData['rowClass'] = 'row_' . $row . ($row == 0 ? ' row_first' : ($row == $max_row - 1 ? ' row_last' : '')) . ($row % 2 == 0 ? ' even' : ' odd'); // Increase the row count if its a password field if ($objField->type == 'password') { ++$row; ++$max_row; $arrData['rowClassConfirm'] = 'row_' . $row . ($row == $max_row - 1 ? ' row_last' : '') . ($row % 2 == 0 ? ' even' : ' odd'); } // Submit buttons do not use the name attribute if ($objField->type == 'submit') { $arrData['name'] = ''; } // Unset the default value depending on the field type (see #4722) if (!empty($arrData['value'])) { if (!in_array('value', trimsplit('[,;]', $GLOBALS['TL_DCA']['tl_form_field']['palettes'][$objField->type]))) { $arrData['value'] = ''; } } /** @var \Widget $objWidget */ $objWidget = new $strClass($arrData); $objWidget->required = $objField->mandatory ? true : false; // HOOK: load form field callback if (isset($GLOBALS['TL_HOOKS']['loadFormField']) && is_array($GLOBALS['TL_HOOKS']['loadFormField'])) { foreach ($GLOBALS['TL_HOOKS']['loadFormField'] as $callback) { $this->import($callback[0]); $objWidget = $this->{$callback}[0]->{$callback}[1]($objWidget, $formId, $this->arrData, $this); } } // Validate the input if (\Input::post('FORM_SUBMIT') == $formId) { $objWidget->validate(); // HOOK: validate form field callback if (isset($GLOBALS['TL_HOOKS']['validateFormField']) && is_array($GLOBALS['TL_HOOKS']['validateFormField'])) { foreach ($GLOBALS['TL_HOOKS']['validateFormField'] as $callback) { $this->import($callback[0]); $objWidget = $this->{$callback}[0]->{$callback}[1]($objWidget, $formId, $this->arrData, $this); } } if ($objWidget->hasErrors()) { $doNotSubmit = true; } elseif ($objWidget->submitInput()) { $arrSubmitted[$objField->name] = $objWidget->value; $_SESSION['FORM_DATA'][$objField->name] = $objWidget->value; unset($_POST[$objField->name]); // see #5474 } } if ($objWidget instanceof \uploadable) { $hasUpload = true; } if ($objWidget instanceof \FormHidden) { $this->Template->hidden .= $objWidget->parse(); --$max_row; continue; } if ($objWidget->name != '' && $objWidget->label != '') { $arrLabels[$objWidget->name] = $this->replaceInsertTags($objWidget->label); // see #4268 } $this->Template->fields .= $objWidget->parse(); ++$row; } } // Process the form data if (\Input::post('FORM_SUBMIT') == $formId && !$doNotSubmit) { $this->processFormData($arrSubmitted, $arrLabels, $arrFields); } // Add a warning to the page title if ($doNotSubmit && !\Environment::get('isAjaxRequest')) { /** @var \PageModel $objPage */ global $objPage; $title = $objPage->pageTitle ?: $objPage->title; $objPage->pageTitle = $GLOBALS['TL_LANG']['ERR']['form'] . ' - ' . $title; $_SESSION['FILES'] = array(); // see #3007 } $strAttributes = ''; $arrAttributes = deserialize($this->attributes, true); if ($arrAttributes[1] != '') { $strAttributes .= ' class="' . $arrAttributes[1] . '"'; } $this->Template->hasError = $doNotSubmit; $this->Template->attributes = $strAttributes; $this->Template->enctype = $hasUpload ? 'multipart/form-data' : 'application/x-www-form-urlencoded'; $this->Template->formId = $arrAttributes[0] ?: 'f' . $this->id; $this->Template->action = \Environment::get('indexFreeRequest'); $this->Template->maxFileSize = $hasUpload ? $this->objModel->getMaxUploadFileSize() : false; $this->Template->novalidate = $this->novalidate ? ' novalidate' : ''; // Get the target URL if ($this->method == 'GET' && $this->jumpTo && ($objTarget = $this->objModel->getRelated('jumpTo')) !== null) { $this->Template->action = $this->generateFrontendUrl($objTarget->row()); } return $this->Template->parse(); }
/** * Add form fields from a back end form generator form ID * * @param int $intId The form generator form ID * @param callable $varCallback Called for each field, return true if you want to include the field in the form * * @return $this * @throws \InvalidArgumentException */ public function addFieldsFromFormGenerator($intId, $varCallback = null) { if (($objFields = \FormFieldModel::findPublishedByPid($intId)) === null) { throw new \InvalidArgumentException('Form ID "' . $intId . '" does not exist or has no published fields.'); } $arrFields = array(); while ($objFields->next()) { // make sure "name" is set because not all form fields do need it and it would thus overwrite the array indexes $strName = $objFields->name ?: 'field_' . $objFields->id; $this->checkFormFieldNameIsValid($strName); $arrDca = $objFields->row(); // Make sure it has a "name" attribute because it is mandatory if (!isset($arrDca['name'])) { $arrDca['name'] = $strName; } if (is_callable($varCallback) && !call_user_func_array($varCallback, array(&$strName, &$arrDca))) { continue; } $this->arrFormFields[$strName] = $arrDca; } $this->intState = self::STATE_DIRTY; return $this; }
/** * Get the data ready for Salesforce * * @access protected * @param array * @param integer * @return array */ protected static function getSalesforceFields($arrSubmitted, $intFormId) { $arrReturn = array(); $objFormFields = \FormFieldModel::findPublishedByPid($intFormId); if ($objFormFields !== null) { while ($objFormFields->next()) { if ($objFormFields->current()->salesforceField) { $arrReturn[$objFormFields->current()->salesforceField] = $arrSubmitted[$objFormFields->current()->name]; } } } return $arrReturn; }
/** * Generate the form * @return string */ protected function compile() { $hasUpload = false; $doNotSubmit = false; $arrSubmitted = array(); $blnAddDateJS = true; $this->loadDataContainer('tl_form_field'); $formId = $this->formID != '' ? 'auto_' . $this->formID : 'auto_form_' . $this->id; $arrUnset = array('FORM_NEXT', 'FORM_BACK'); foreach ($arrUnset as $strKey) { unset($_SESSION['FORM_DATA'][$strKey]); } // Form is used to edit existing formdata record if ($this->objEditRecord instanceof \Database\Result) { $arrEditRecord = $this->objEditRecord->row(); $this->blnEditform = true; $this->import('Formdata'); } // Check if the form is a multipage form $objPaginators = \Database::getInstance()->prepare("SELECT id,pid,invisible,`sorting`,`type`,`name`,`label`,`value`,`imageSubmit`,`singleSRC`,`sLabel`,`efgAddBackButton`,`efgBackStoreSessionValues`,`efgBackSlabel`,`efgBackImageSubmit`,`efgBackSingleSRC` FROM tl_form_field WHERE pid=? AND `type`=?" . (!BE_USER_LOGGED_IN ? " AND invisible=''" : "") . " ORDER BY `sorting`")->execute($this->id, 'efgFormPaginator'); if ($objPaginators->numRows) { $this->blnMultipage = true; $this->intTotalPages = (int) $objPaginators->numRows; while ($objPaginators->next()) { $this->arrPaginators[] = $objPaginators->row(); } } // Use the core class Form if this is not a multi page form and not frontend edit form if (!$this->blnMultipage && !$this->blnEditform || $this->method == 'GET' || TL_MODE == 'BE') { // unset files in session to avoid wrong validation and submission of file uploads // .. files may be stored in session after frontend editing or submission of multi page form $_SESSION['FILES'] = array(); $this->strTemplate = 'form'; return parent::compile(); } global $objPage; if ($objPage->outputFormat == 'html5') { $blnIsHtml5 = true; } $this->blnAllowSkipRequired = false; // allow form submission, if ALL required fields are empty $this->arrWidgetsFailedValidation = array(); // validation result of required widgets $doNotValidate = false; $strMode = ''; $intActivePage = 1; $this->Template = new \FrontendTemplate($this->strTemplate); \System::loadLanguageFile('tl_form'); // render a previous completed page if (strlen($_SESSION['EFP'][$formId]['render_page'])) { $intActivePage = (int) $_SESSION['EFP'][$formId]['render_page']; $this->intActivePage = (int) $_SESSION['EFP'][$formId]['render_page']; $strMode = 'reload'; unset($_SESSION['EFP'][$formId]['render_page']); } elseif (!strlen($_POST['FORM_SUBMIT'])) { unset($_SESSION['EFP'][$formId]['render_page']); unset($_SESSION['EFP'][$formId]['completed']); } if (\Input::post('FORM_SUBMIT') == $formId && (strlen($_POST['FORM_PAGE']) || is_array($_POST['FORM_STEP']))) { $intActivePage = (int) $_POST['FORM_PAGE']; $intGoto = 0; if (strlen($_POST['FORM_BACK']) || strlen($_POST['FORM_BACK_x'])) { $intActivePage = (int) $_POST['FORM_PAGE']; $doNotValidate = true; $strMode = 'back'; } elseif (is_array($_POST['FORM_STEP']) || is_array($_POST['FORM_STEP_x'])) { $intGoto = is_array($_POST['FORM_STEP']) ? key($_POST['FORM_STEP']) : key($_POST['FORM_STEP_x']); if ($intGoto < $intActivePage) { $_SESSION['EFP'][$formId]['render_page'] = $intGoto < 1 ? 1 : $intGoto; \Controller::reload(); } elseif ($intGoto > $intActivePage && $_SESSION['EFP'][$formId]['completed']['page_' . $intGoto]) { $_SESSION['EFP'][$formId]['render_page'] = $intGoto; \Controller::reload(); } } if ($intActivePage < 1) { $intActivePage = 1; } if ($intActivePage > $this->intTotalPages) { $intActivePage = $this->intTotalPages; } $this->intActivePage = $intActivePage; } $this->Template->fields = ''; $this->Template->hidden = ''; $this->Template->formSubmit = $formId; $this->Template->tableless = $this->tableless ? true : false; $this->Template->method = $this->method == 'GET' ? 'get' : 'post'; if ($this->blnMultipage || $this->blnEditform) { $objPageWidget = new \FormHidden(array('name' => 'FORM_PAGE', 'value' => $this->intActivePage)); $this->Template->hidden .= $objPageWidget->parse(); } $this->initializeSession($formId); $arrLabels = array(); // Get all form fields $arrFields = array(); $objFields = \FormFieldModel::findPublishedByPid($this->id); if ($objFields !== null) { while ($objFields->next()) { $arrFields[] = $objFields->current(); } } // HOOK: compile form fields if (isset($GLOBALS['TL_HOOKS']['compileFormFields']) && is_array($GLOBALS['TL_HOOKS']['compileFormFields'])) { foreach ($GLOBALS['TL_HOOKS']['compileFormFields'] as $callback) { $this->import($callback[0]); $arrFields = $this->{$callback}[0]->{$callback}[1]($arrFields, $formId, $this); } } // Process the fields if (!empty($arrFields) && is_array($arrFields)) { $row = 0; $max_row = count($arrFields); foreach ($arrFields as $objField) { // Skip fields outside range of active page if ($this->intTotalPages > 1 && ($this->blnMultipage || $this->blnEditform)) { $intFieldSorting = (int) $objField->sorting; if ($this->intActivePage <= 1 && $intFieldSorting > (int) $this->arrPaginators[$this->intActivePage - 1]['sorting']) { continue; } elseif ($this->intActivePage > 1 && $this->intActivePage < $this->intTotalPages && ($intFieldSorting <= (int) $this->arrPaginators[$this->intActivePage - 2]['sorting'] || $intFieldSorting > (int) $this->arrPaginators[$this->intActivePage - 1]['sorting'])) { continue; } elseif ($this->intActivePage == $this->intTotalPages && $intFieldSorting <= (int) $this->arrPaginators[$this->intActivePage - 2]['sorting']) { continue; } } $strClass = $GLOBALS['TL_FFL'][$objField->type]; // Continue if the class is not defined if (!class_exists($strClass)) { continue; } $arrData = $objField->row(); $arrData['decodeEntities'] = true; $arrData['allowHtml'] = $this->allowTags; $arrData['rowClass'] = 'row_' . $row . ($row == 0 ? ' row_first' : ($row == $max_row - 1 ? ' row_last' : '')) . ($row % 2 == 0 ? ' even' : ' odd'); $arrData['tableless'] = $this->tableless; if ($this->blnMultipage || $this->blnEditform) { $arrData['formMultipage'] = $this->blnMultipage; $arrData['formActivePage'] = $this->intActivePage; $arrData['formTotalPages'] = $this->intTotalPages; } // Increase the row count if it is a password field if ($objField->type == 'password') { ++$row; ++$max_row; $arrData['rowClassConfirm'] = 'row_' . $row . ($row == $max_row - 1 ? ' row_last' : '') . ($row % 2 == 0 ? ' even' : ' odd'); } // Submit buttons do not use the name attribute if ($objField->type == 'submit') { $arrData['name'] = ''; } $objWidget = new $strClass($arrData); $objWidget->required = $objField->mandatory ? true : false; if ($objWidget->required) { $this->arrWidgetsFailedValidation[$objField->name] = 0; } // Unset session values if no FORM_SUBMIT or form page has not been completed // (to avoid wrong validation against session values and to avoid usage of values of other forms): // This behaviour can be deactivated by setting: $GLOBALS['EFP'][$formId]['doNotCleanStoredSessionData'] = true; if ($strMode != 'reload' && strlen($objField->name)) { if (!strlen($_POST['FORM_SUBMIT']) || !$_SESSION['EFP'][$formId]['completed']['page_' . $this->intActivePage]) { if (!$GLOBALS['EFP'][$formId]['doNotCleanStoredSessionData']) { unset($_SESSION['FORM_DATA'][$objField->name]); } if ($objWidget instanceof \uploadable) { unset($_SESSION['FILES'][$objField->name]); } } } // Always populate from existing session data if configured if ($GLOBALS['EFP'][$formId]['doNotCleanStoredSessionData'] == true && isset($_SESSION['FORM_DATA'][$objField->name])) { $objWidget->value = $_SESSION['FORM_DATA'][$objField->name]; } if ($strMode == 'reload' || $this->blnEditform && !strlen($_POST['FORM_BACK']) && !strlen($_POST['FORM_BACK_x'])) { // Frontend editing if ($this->blnEditform && !$_SESSION['EFP'][$formId]['completed']['page_' . $this->intActivePage]) { if (is_array($objWidget->options)) { $arrData['options'] = $objWidget->options; } // Prepare options array $arrData['options'] = $this->Formdata->prepareWidgetOptions($arrData); // Set rgxp 'date' for field type 'calendar' if not set if ($arrData['type'] == 'calendar') { if (!isset($arrData['rgxp'])) { $arrData['rgxp'] = 'date'; } } elseif ($arrData['type'] == 'xdependentcalendarfields') { $arrData['rgxp'] = 'date'; $arrData['dateFormat'] = $arrData['xdateformat']; } if ($objWidget instanceof \uploadable) { unset($_SESSION['FILES'][$objField->name]); } // Prepare value $varFieldValue = $this->Formdata->prepareDatabaseValueForWidget($arrEditRecord[$objField->name], $arrData); $objWidget->value = $varFieldValue; } else { // Populate field if page has been completed if ($_SESSION['EFP'][$formId]['completed']['page_' . $this->intActivePage] == true) { $objWidget->value = $_SESSION['FORM_DATA'][$objField->name]; } else { if ($objWidget instanceof \uploadable) { unset($_SESSION['FILES'][$objField->name]); } } } } // HOOK: Load form field callback if (!strlen($_POST['FORM_BACK']) && !strlen($_POST['FORM_BACK_x'])) { if (isset($GLOBALS['TL_HOOKS']['loadFormField']) && is_array($GLOBALS['TL_HOOKS']['loadFormField'])) { foreach ($GLOBALS['TL_HOOKS']['loadFormField'] as $callback) { $this->import($callback[0]); $objWidget = $this->{$callback}[0]->{$callback}[1]($objWidget, $formId, $this->arrData); } } } // Validate the input if (\Input::post('FORM_SUBMIT') == $formId) { // Populate field if (strlen($_POST['FORM_BACK']) || strlen($_POST['FORM_BACK_x'])) { if ($strMode == 'back' && strlen($this->arrPaginators[$this->intActivePage - 1]['efgBackStoreSessionValues'])) { unset($_SESSION['FORM_DATA'][$objField->name]); $objWidget->value = \Input::post($objField->name); } elseif ($_SESSION['EFP'][$formId]['completed']['page_' . $this->intActivePage] == true) { $objWidget->value = $_SESSION['FORM_DATA'][$objField->name]; unset($_SESSION['FORM_DATA'][$objField->name]); } } if (!$doNotValidate) { if ($objWidget instanceof \uploadable) { // If the widget does not store the file, store it in tmp folder and session to make it available for mails etc. if (!$objWidget->storeFile) { if ($this->intActivePage <= $this->intTotalPages) { // Unset the file in session, if this page has not been completed if (!$_SESSION['EFP'][$formId]['completed']['page_' . $this->intActivePage]) { unset($_SESSION['FILES'][$objField->name]); } $objWidget->validate(); // File has been uploaded, store it in temp folder if (is_uploaded_file($_SESSION['FILES'][$objField->name]['tmp_name'])) { $this->import('Files'); $strDstFile = TL_ROOT . '/system/tmp/' . md5_file($_SESSION['FILES'][$objField->name]['tmp_name']); if (@copy($_SESSION['FILES'][$objField->name]['tmp_name'], $strDstFile)) { $_SESSION['FILES'][$objField->name]['tmp_name'] = $strDstFile; $_SESSION['FILES'][$objField->name]['uploaded'] = true; $this->Files->chmod($strDstFile, 0644); } } } } else { $objWidget->validate(); } } else { $objWidget->validate(); } // HOOK: validate form field callback if (isset($GLOBALS['TL_HOOKS']['validateFormField']) && is_array($GLOBALS['TL_HOOKS']['validateFormField'])) { foreach ($GLOBALS['TL_HOOKS']['validateFormField'] as $callback) { $this->import($callback[0]); $objWidget = $this->{$callback}[0]->{$callback}[1]($objWidget, $formId, $this->arrData); } } } if ($objWidget->hasErrors()) { if ($objWidget->required) { $this->arrWidgetsFailedValidation[$objField->name] = 1; } $doNotSubmit = true; } elseif ($objWidget->submitInput() || $strMode == 'back') { if ($objWidget->submitInput()) { $arrSubmitted[$objField->name] = $objWidget->value; $_SESSION['FORM_DATA'][$objField->name] = $objWidget->value; unset($_POST[$objField->name]); // see #5474 } } } if ($objWidget instanceof \FormHidden) { $this->Template->hidden .= $objWidget->parse(); continue; } if ($objWidget instanceof \uploadable) { $hasUpload = true; if ($this->blnMultipage || $this->blnEditform) { // Save file info in the session in frontend edit mode if ($this->blnEditform && strlen($arrEditRecord[$objField->name]) && (!isset($_SESSION['FILES'][$objField->name]) || empty($_SESSION['FILES'][$objField->name]))) { $objFile = new \File($arrEditRecord[$objField->name]); if ($objFile->size) { $_SESSION['FILES'][$objField->name] = array('name' => $objFile->basename, 'type' => $objFile->mime, 'tmp_name' => TL_ROOT . '/' . $objFile->value, 'size' => $objFile->size, 'uploaded' => true); } } // Add info about uploaded file to upload input if (isset($_SESSION['FILES'][$objField->name]) && $_SESSION['FILES'][$objField->name]['uploaded']) { $this->Template->fields .= preg_replace('/(.*?)(<input.*?>)(.*?)/sim', '$1<p class="upload_info">' . sprintf($GLOBALS['TL_LANG']['MSC']['fileUploaded'], $_SESSION['FILES'][$objField->name]['name']) . '</p>$2$3', $objWidget->parse()); ++$row; continue; } } } if ($objWidget->name != '' && $objWidget->label != '') { $arrLabels[$objWidget->name] = $this->replaceInsertTags($objWidget->label); } $this->Template->fields .= $objWidget->parse(); ++$row; } } if ($doNotSubmit && $this->blnAllowSkipRequired) { if (!empty($this->arrWidgetsFailedValidation) && count(array_count_values($this->arrWidgetsFailedValidation)) == 1) { $doNotSubmit = false; } } // Process form data if (\Input::post('FORM_SUBMIT') == $formId && !$doNotSubmit) { if ($this->intTotalPages == 1 || !$this->blnMultipage && !$this->blnEditform) { $this->processFormData($arrSubmitted, $arrLabels); } else { // If not last page but page is completed, render next page if ($this->intActivePage < $this->intTotalPages && (strlen($_POST['FORM_NEXT']) || strlen($_POST['FORM_NEXT_x']))) { $_SESSION['EFP'][$formId]['render_page'] = (int) $_POST['FORM_PAGE'] + 1; $_SESSION['EFP'][$formId]['completed']['page_' . $_POST['FORM_PAGE']] = true; \Controller::reload(); } elseif ($strMode == 'back' && $this->intActivePage <= $this->intTotalPages && (strlen($_POST['FORM_BACK']) || strlen($_POST['FORM_BACK_x']))) { $_SESSION['EFP'][$formId]['render_page'] = (int) $_POST['FORM_PAGE'] - 1; $_SESSION['EFP'][$formId]['completed']['page_' . $_POST['FORM_PAGE']] = true; \Controller::reload(); } else { if ((int) $_POST['FORM_PAGE'] == $this->intTotalPages && (strlen($_POST['FORM_NEXT']) || strlen($_POST['FORM_NEXT_x']))) { unset($_SESSION['EFP'][$formId]['render_page']); unset($_SESSION['EFP'][$formId]['completed']); unset($_SESSION['FORM_DATA']['FORM_PAGE']); unset($_SESSION['FORM_DATA']['FORM_NEXT']); unset($_SESSION['FORM_DATA']['FORM_BACK']); // Populate arrSubmitted from session $arrSubmitted = $_SESSION['FORM_DATA']; $this->processFormData($arrSubmitted, $arrLabels); } } } } $strAttributes = ''; $arrAttributes = deserialize($this->attributes, true); // Add a css class if ($this->blnMultipage) { $arrAttributes[1] = trim($arrAttributes[1] . ' multipage form_page_' . $this->intActivePage); } if (strlen($arrAttributes[1])) { $strAttributes .= ' class="' . $arrAttributes[1] . '"'; } $this->Template->hasError = $doNotSubmit; $this->Template->attributes = $strAttributes; $this->Template->enctype = $hasUpload ? 'multipart/form-data' : 'application/x-www-form-urlencoded'; $this->Template->formId = strlen($arrAttributes[0]) ? $arrAttributes[0] : 'f' . $this->id; $this->Template->action = \Environment::get('indexFreeRequest'); $this->Template->maxFileSize = $hasUpload ? $this->objModel->getMaxUploadFileSize() : false; $this->Template->novalidate = $this->novalidate ? ' novalidate' : ''; // Get the target URL if ($this->method == 'GET' && $this->jumpTo && ($objTarget = $this->objModel->getRelated('jumpTo')) !== null) { $this->Template->action = $this->generateFrontendUrl($objTarget->row()); } // Add Javascript to handle html5 input attribute 'required' on back button if ($blnIsHtml5) { $this->Template->fields .= ' <script>' . $this->getBackButtonJavascriptString() . ' </script>'; } if ($blnAddDateJS) { $this->Template->fields .= ' <script' . (!$blnIsHtml5 ? ' type="text/javascript"' : '') . '>' . $this->getDateString() . ' </script>'; } return $this->Template->parse(); }
/** * Get the form postdata * * @param int $formId * * @return array */ protected function getFormPostData($formId) { static $data; if (!is_array($data)) { $data = array(); $fieldModels = \FormFieldModel::findPublishedByPid($formId); if ($fieldModels !== null) { foreach ($fieldModels as $fieldModel) { $data[$fieldModel->name] = \Input::post($fieldModel->name); } } } return $data; }
public function processFormDataHook($arrSubmitted, $arrData, $arrFiles, $arrLabels, $objForm) { $formId = $objForm->formID != '' ? 'auto_' . $objForm->formID : 'auto_form_' . $objForm->id; // Get all form fields $arrFields = array(); $objFields = \FormFieldModel::findPublishedByPid($objForm->id); // default order by sorting $strReturn = null; if ($objFields !== null) { $start = false; while ($objFields->next()) { if ($objFields->successType == 'successStart') { $start = true; } if ($start || !$objForm->hideFormOnSuccess) { $arrFields[] = $objFields->current(); } if ($objFields->successType == 'successStop') { $start = false; // hideFormOnSuccess: do not render other fields than successStart, fields inside and successStop if ($objForm->hideFormOnSuccess) { break; } } } } if (!empty($arrFields) && is_array($arrFields)) { $row = 0; $max_row = count($arrFields); foreach ($arrFields as $objField) { $strClass = $GLOBALS['TL_FFL'][$objField->type]; // Continue if the class is not defined if (!class_exists($strClass)) { continue; } $arrData = $objField->row(); $arrData['decodeEntities'] = true; $arrData['allowHtml'] = $objForm->allowTags; $arrData['rowClass'] = 'row_' . $row . ($row == 0 ? ' row_first' : ($row == $max_row - 1 ? ' row_last' : '')) . ($row % 2 == 0 ? ' even' : ' odd'); $arrData['tableless'] = $objForm->tableless; // Increase the row count if its a password field if ($objField->type == 'password') { ++$row; ++$max_row; $arrData['rowClassConfirm'] = 'row_' . $row . ($row == $max_row - 1 ? ' row_last' : '') . ($row % 2 == 0 ? ' even' : ' odd'); } // Submit buttons do not use the name attribute if ($objField->type == 'submit') { $arrData['name'] = ''; } // Unset the default value depending on the field type (see #4722) if (!empty($arrData['value'])) { if (!in_array('value', trimsplit('[,;]', $GLOBALS['TL_DCA']['tl_form_field']['palettes'][$objField->type]))) { $arrData['value'] = ''; } } $objWidget = new $strClass($arrData); $objWidget->required = $objField->mandatory ? true : false; // HOOK: load form field callback if (isset($GLOBALS['TL_HOOKS']['loadFormField']) && is_array($GLOBALS['TL_HOOKS']['loadFormField'])) { foreach ($GLOBALS['TL_HOOKS']['loadFormField'] as $callback) { $this->import($callback[0]); $objWidget = $this->{$callback}[0]->{$callback}[1]($objWidget, $formId, $arrData, $objForm); } } $strReturn .= $objWidget->parse(); ++$row; } } if ($objForm->isAjaxForm && !is_null($strReturn)) { $strReturn .= '<input type="hidden" name="FORM_SUBMIT" value="' . $formId . '">'; $strReturn .= '<input type="hidden" name="REQUEST_TOKEN" value="' . \RequestToken::get() . '">'; die(\Controller::replaceInsertTags($strReturn)); } }
/** * Loads the form field models (calling the compileFormFields hook and ignoring itself). */ private function loadFormFieldModels() { $formFieldModels = \FormFieldModel::findPublishedByPid($this->formModel->id); if (null === $formFieldModels) { $formFieldModels = []; } else { $formFieldModels = $formFieldModels->getModels(); } // Needed for the hook $form = $this->createDummyForm(); if (isset($GLOBALS['TL_HOOKS']['compileFormFields']) && is_array($GLOBALS['TL_HOOKS']['compileFormFields'])) { foreach ($GLOBALS['TL_HOOKS']['compileFormFields'] as $k => $callback) { // Do not call ourselves recursively if ('MPForms' === $callback[0]) { continue; } $objCallback = \System::importStatic($callback[0]); $formFieldModels = $objCallback->{$callback[1]}($formFieldModels, $this->getFormId(), $form); } } $this->formFieldModels = $formFieldModels; }