/** * Replace string with tags that reference fields * * @param string $text Text to process * * @return string Text with tags replace */ protected function parseFieldTags($text) { $ret = $text; // Replace [ITEM:ID] in the URL with the item's key value (usually: // the auto-incrementing numeric ID) if (is_null($this->item)) { $this->item = $this->form->getModel(); } $replace = $this->item->getId(); $ret = str_replace('[ITEM:ID]', $replace, $ret); // Replace the [ITEMID] in the URL with the current Itemid parameter $ret = str_replace('[ITEMID]', $this->form->getContainer()->input->getInt('Itemid', 0), $ret); // Replace the [TOKEN] in the URL with the Joomla! form token $ret = str_replace('[TOKEN]', \JFactory::getSession()->getFormToken(), $ret); // Replace other field variables in the URL $data = $this->item->getData(); foreach ($data as $field => $value) { // Skip non-processable values if (is_array($value) || is_object($value)) { continue; } $search = '[ITEM:' . strtoupper($field) . ']'; $ret = str_replace($search, $value, $ret); } return $ret; }
/** * Renders a Form for an Edit view and returns the corresponding HTML * * @param Form &$form The form to render * @param DataModel $model The model providing our data * * @return string The HTML rendering of the form */ public function renderFormEdit(Form &$form, DataModel $model) { // Get the key for this model's table $key = $model->getKeyName(); $keyValue = $model->getId(); $html = ''; $validate = strtolower($form->getAttribute('validate')); if (in_array($validate, array('true', 'yes', '1', 'on'))) { \JHTML::_('behavior.formvalidation'); $class = ' form-validate'; $this->loadValidationScript($form); } else { $class = ''; } // Check form enctype. Use enctype="multipart/form-data" to upload binary files in your form. $template_form_enctype = $form->getAttribute('enctype'); if (!empty($template_form_enctype)) { $enctype = ' enctype="' . $form->getAttribute('enctype') . '" '; } else { $enctype = ''; } // Check form name. Use name="yourformname" to modify the name of your form. $formname = $form->getAttribute('name'); if (empty($formname)) { $formname = 'adminForm'; } // Check form ID. Use id="yourformname" to modify the id of your form. $formid = $form->getAttribute('id'); if (empty($formid)) { $formid = $formname; } // Check if we have a custom task $customTask = $form->getAttribute('customTask'); if (empty($customTask)) { $customTask = ''; } // Get the form action URL $platform = $this->container->platform; $actionUrl = $platform->isBackend() ? 'index.php' : \JUri::root() . 'index.php'; $itemid = $this->container->input->getCmd('Itemid', 0); if ($platform->isFrontend() && $itemid != 0) { $uri = new \JUri($actionUrl); if ($itemid) { $uri->setVar('Itemid', $itemid); } $actionUrl = \JRoute::_($uri->toString()); } $html .= '<form action="' . $actionUrl . '" method="post" name="' . $formname . '" id="' . $formid . '"' . $enctype . ' class="form-horizontal' . $class . '">' . "\n"; $html .= "\t" . '<input type="hidden" name="option" value="' . $this->container->componentName . '" />' . "\n"; $html .= "\t" . '<input type="hidden" name="view" value="' . $form->getView()->getName() . '" />' . "\n"; $html .= "\t" . '<input type="hidden" name="task" value="' . $customTask . '" />' . "\n"; $html .= "\t" . '<input type="hidden" name="' . $key . '" value="' . $keyValue . '" />' . "\n"; $html .= "\t" . '<input type="hidden" name="' . \JFactory::getSession()->getFormToken() . '" value="1" />' . "\n"; $html .= $this->renderFormRaw($form, $model, 'edit'); $html .= '</form>'; return $html; }