Example #1
0
 /**
  * Renders a F0FForm and returns the corresponding HTML
  *
  * @param   F0FForm   &$form     The form to render
  * @param   F0FModel  $model     The model providing our data
  * @param   F0FInput  $input     The input object
  * @param   string    $formType  The form type: edit, browse or read
  * @param   boolean   $raw       If true, the raw form fields rendering (without the surrounding form tag) is returned.
  *
  * @return  string    The HTML rendering of the form
  */
 public function renderForm(F0FForm &$form, F0FModel $model, F0FInput $input, $formType = null, $raw = false)
 {
     if (is_null($formType)) {
         $formType = $form->getAttribute('type', 'edit');
     } else {
         $formType = strtolower($formType);
     }
     switch ($formType) {
         case 'browse':
             return $this->renderFormBrowse($form, $model, $input);
             break;
         case 'read':
             if ($raw) {
                 return $this->renderFormRaw($form, $model, $input, 'read');
             } else {
                 return $this->renderFormRead($form, $model, $input);
             }
             break;
         default:
             if ($raw) {
                 return $this->renderFormRaw($form, $model, $input, 'edit');
             } else {
                 return $this->renderFormEdit($form, $model, $input);
             }
             break;
     }
 }
Example #2
0
 /**
  * Renders a F0FForm for an Edit view and returns the corresponding HTML
  *
  * @param   F0FForm   &$form  The form to render
  * @param   F0FModel  $model  The model providing our data
  * @param   F0FInput  $input  The input object
  *
  * @return  string    The HTML rendering of the form
  */
 protected function renderFormEdit(F0FForm &$form, F0FModel $model, F0FInput $input)
 {
     // Get the key for this model's table
     $key = $model->getTable()->getKeyName();
     $keyValue = $model->getId();
     JHTML::_('behavior.tooltip');
     $html = '';
     $validate = strtolower($form->getAttribute('validate'));
     $class = '';
     if (in_array($validate, array('true', 'yes', '1', 'on'))) {
         JHtml::_('behavior.formvalidation');
         $class = 'form-validate ';
         $this->loadValidationScript($form);
     }
     // 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('name');
     if (empty($formid)) {
         $formid = 'adminForm';
     }
     // Check if we have a custom task
     $customTask = $form->getAttribute('customTask');
     if (empty($customTask)) {
         $customTask = '';
     }
     // Get the form action URL
     $actionUrl = F0FPlatform::getInstance()->isBackend() ? 'index.php' : JUri::root() . 'index.php';
     if (F0FPlatform::getInstance()->isFrontend() && $input->getCmd('Itemid', 0) != 0) {
         $itemid = $input->getCmd('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="' . $class . '">' . PHP_EOL;
     $html .= "\t" . '<input type="hidden" name="option" value="' . $input->getCmd('option') . '" />' . PHP_EOL;
     $html .= "\t" . '<input type="hidden" name="view" value="' . $input->getCmd('view', 'edit') . '" />' . PHP_EOL;
     $html .= "\t" . '<input type="hidden" name="task" value="' . $customTask . '" />' . PHP_EOL;
     $html .= "\t" . '<input type="hidden" name="' . $key . '" value="' . $keyValue . '" />' . PHP_EOL;
     $html .= "\t" . '<input type="hidden" name="' . JFactory::getSession()->getFormToken() . '" value="1" />' . PHP_EOL;
     $html .= $this->renderFormRaw($form, $model, $input, 'edit');
     $html .= '</form>';
     return $html;
 }
Example #3
0
 /**
  * Renders a raw F0FForm and returns the corresponding HTML
  *
  * @param   F0FForm   &$form     The form to render
  * @param   F0FModel  $model     The model providing our data
  * @param   F0FInput  $input     The input object
  * @param   string    $formType  The form type e.g. 'edit' or 'read'
  *
  * @return  string    The HTML rendering of the form
  */
 protected function renderFormRaw(F0FForm &$form, F0FModel $model, F0FInput $input, $formType)
 {
     $html = '';
     // Do we have a tabbed form?
     $isTabbed = $form->getAttribute('tabbed', '0');
     $isTabbed = in_array($isTabbed, array('true', 'yes', 'on', '1'));
     // If the form is tabbed, render the tabs bars
     if ($isTabbed) {
         $html .= '<ul class="nav nav-tabs">' . "\n";
         foreach ($form->getFieldsets() as $fieldset) {
             // Only create tabs for tab fieldsets
             $isTabbedFieldset = $this->isTabFieldset($fieldset);
             if (!$isTabbedFieldset) {
                 continue;
             }
             // Only create tabs if we do have a label
             if (!isset($fieldset->label) || empty($fieldset->label)) {
                 continue;
             }
             $label = JText::_($fieldset->label);
             $name = $fieldset->name;
             $liClass = $isTabbedFieldset == 2 ? 'class="active"' : '';
             $html .= "<li {$liClass}><a href=\"#{$name}\" data-toggle=\"tab\">{$label}</a></li>\n";
         }
         $html .= '</ul>' . "\n\n<div class=\"tab-content\">\n";
         foreach ($form->getFieldsets() as $fieldset) {
             if (!$this->isTabFieldset($fieldset)) {
                 continue;
             }
             $html .= $this->renderFieldset($fieldset, $form, $model, $input, $formType, false);
         }
         $html .= "</div>\n";
     }
     foreach ($form->getFieldsets() as $fieldset) {
         if ($isTabbed && $this->isTabFieldset($fieldset)) {
             continue;
         }
         $html .= $this->renderFieldset($fieldset, $form, $model, $input, $formType, false);
     }
     return $html;
 }