/**
  * Renders a FOFForm and returns the corresponding HTML
  *
  * @param   FOFForm   &$form     The form to render
  * @param   FOFModel  $model     The model providing our data
  * @param   FOFInput  $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(FOFForm &$form, FOFModel $model, FOFInput $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;
     }
 }
Exemplo n.º 2
0
 protected function preprocessForm(FOFForm $form, $data, $group = 'content')
 {
     $form_file = JPATH_COMPONENT_ADMINISTRATOR . "/models/forms/standard.xml";
     $form->loadFile($form_file, false, false);
     $app = JFactory::getApplication();
     $data_ = $app->getUserState('com_redslider.edit.slide.data');
     if ($data_) {
         if ($data_['type'] != 'standard') {
             $form_file_type = JPATH_COMPONENT_ADMINISTRATOR . "/models/forms/" . $data_['type'] . ".xml";
             $form->loadFile($form_file_type, false, false);
         }
     } else {
         if ($data['type'] != 'standard') {
             $form_file_type = JPATH_COMPONENT_ADMINISTRATOR . "/models/forms/" . $data['type'] . ".xml";
             $form->loadFile($form_file_type, false, false);
         }
     }
     // Trigger the default form events.
     parent::preprocessForm($form, $data, $group);
 }
 /**
  * Renders a raw FOFForm and returns the corresponding HTML
  *
  * @param   FOFForm   &$form     The form to render
  * @param   FOFModel  $model     The model providing our data
  * @param   FOFInput  $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(FOFForm &$form, FOFModel $model, FOFInput $input, $formType)
 {
     $html = '';
     foreach ($form->getFieldsets() as $fieldset) {
         $fields = $form->getFieldset($fieldset->name);
         if (isset($fieldset->class)) {
             $class = 'class="' . $fieldset->class . '"';
         } else {
             $class = '';
         }
         $html .= "\t" . '<div id="' . $fieldset->name . '" ' . $class . '>' . PHP_EOL;
         if (isset($fieldset->label) && !empty($fieldset->label)) {
             $html .= "\t\t" . '<h3>' . JText::_($fieldset->label) . '</h3>' . PHP_EOL;
         }
         foreach ($fields as $field) {
             $required = $field->required;
             $labelClass = $field->labelClass;
             $groupClass = $form->getFieldAttribute($field->fieldname, 'groupclass', '', $field->group);
             // Auto-generate label and description if needed
             // Field label
             $title = $form->getFieldAttribute($field->fieldname, 'label', '', $field->group);
             $emptylabel = $form->getFieldAttribute($field->fieldname, 'emptylabel', false, $field->group);
             if (empty($title) && !$emptylabel) {
                 $model->getName();
                 $title = strtoupper($input->get('option') . '_' . $model->getName() . '_' . $field->id . '_LABEL');
             }
             // Field description
             $description = $form->getFieldAttribute($field->fieldname, 'description', '', $field->group);
             /**
              * The following code is backwards incompatible. Most forms don't require a description in their form
              * fields. Having to use emptydescription="1" on each one of them is an overkill. Removed.
              */
             /*
             $emptydescription   = $form->getFieldAttribute($field->fieldname, 'emptydescription', false, $field->group);
             if (empty($description) && !$emptydescription)
             {
             	$description = strtoupper($input->get('option') . '_' . $model->getName() . '_' . $field->id . '_DESC');
             }
             */
             if ($formType == 'read') {
                 $inputField = $field->static;
             } elseif ($formType == 'edit') {
                 $inputField = $field->input;
             }
             if (empty($title)) {
                 $html .= "\t\t\t" . $inputField . PHP_EOL;
                 if (!empty($description) && $formType == 'edit') {
                     $html .= "\t\t\t\t" . '<span class="help-block">';
                     $html .= JText::_($description) . '</span>' . PHP_EOL;
                 }
             } else {
                 $html .= "\t\t\t" . '<div class="control-group ' . $groupClass . '">' . PHP_EOL;
                 $html .= "\t\t\t\t" . '<label class="control-label ' . $labelClass . '" for="' . $field->id . '">' . PHP_EOL;
                 $html .= "\t\t\t\t" . JText::_($title) . PHP_EOL;
                 if ($required) {
                     $html .= ' *';
                 }
                 $html .= "\t\t\t\t" . '</label>' . PHP_EOL;
                 $html .= "\t\t\t\t" . '<div class="controls">' . PHP_EOL;
                 $html .= "\t\t\t\t" . $inputField . PHP_EOL;
                 if (!empty($description)) {
                     $html .= "\t\t\t\t" . '<span class="help-block">';
                     $html .= JText::_($description) . '</span>' . PHP_EOL;
                 }
                 $html .= "\t\t\t\t" . '</div>' . PHP_EOL;
                 $html .= "\t\t\t" . '</div>' . PHP_EOL;
             }
         }
         $html .= "\t" . '</div>' . PHP_EOL;
     }
     return $html;
 }
Exemplo n.º 4
0
    /**
     * Loads the validation script for an edit form
     *
     * @param   FOFForm  &$form  The form we are rendering
     *
     * @return  void
     */
    protected function loadValidationScript(FOFForm &$form)
    {
        $message = $form->getView()->escape(JText::_('JGLOBAL_VALIDATION_FORM_FAILED'));
        $js = <<<ENDJAVASCRIPT
Joomla.submitbutton = function(task)
{
\tif (task == 'cancel' || document.formvalidator.isValid(document.id('adminForm')))
\t{
\t\tJoomla.submitform(task, document.getElementById('adminForm'));
\t}
\telse {
\t\talert('{$message}');
\t}
};
ENDJAVASCRIPT;
        $document = FOFPlatform::getInstance()->getDocument();
        if ($document instanceof JDocument) {
            $document->addScriptDeclaration($js);
        }
    }
Exemplo n.º 5
0
 /**
  * Get the filter value for this header field
  *
  * @return  mixed  The filter value
  */
 protected function getValue()
 {
     $model = $this->form->getModel();
     return $model->getState($this->filterSource);
 }
 /**
  * Renders a label for a fieldset.
  *
  * @param   object  	$field  	The field of the label to render
  * @param   FOFForm   	&$form      The form to render
  * @param 	string		$title		The title of the label
  *
  * @return 	string		The rendered label
  */
 protected function renderFieldsetLabel($field, FOFForm &$form, $title)
 {
     $html = '';
     $labelClass = $field->labelClass ? $field->labelClass : $field->labelclass;
     // Joomla! 2.5/3.x use different case for the same name
     $required = $field->required;
     $tooltip = $form->getFieldAttribute($field->fieldname, 'tooltip', '', $field->group);
     if (!empty($tooltip)) {
         JHtml::_('bootstrap.tooltip');
         $tooltipText = '<strong>' . JText::_($title) . '</strong><br />' . JText::_($tooltip);
         $html .= "\t\t\t\t" . '<label class="control-label hasTooltip ' . $labelClass . '" for="' . $field->id . '" title="' . $tooltipText . '" rel="tooltip">';
     } else {
         $html .= "\t\t\t\t" . '<label class="control-label ' . $labelClass . '" for="' . $field->id . '">';
     }
     $html .= JText::_($title);
     if ($required) {
         $html .= ' *';
     }
     $html .= '</label>' . PHP_EOL;
     return $html;
 }
Exemplo n.º 7
0
 /**
  * Method to validate the form data.
  *
  * @param   FOFForm  $form   The form to validate against.
  * @param   array    $data   The data to validate.
  * @param   string   $group  The name of the field group to validate.
  *
  * @return  mixed   Array of filtered data if valid, false otherwise.
  *
  * @see     JFormRule
  * @see     JFilterInput
  * @since   2.0
  */
 public function validateForm($form, $data, $group = null)
 {
     // Filter and validate the form data.
     $data = $form->filter($data);
     $return = $form->validate($data, $group);
     // Check for an error.
     if ($return instanceof Exception) {
         $this->setError($return->getMessage());
         return false;
     }
     // Check the validation results.
     if ($return === false) {
         // Get the validation messages from the form.
         foreach ($form->getErrors() as $message) {
             if ($message instanceof Exception) {
                 $this->setError($message->getMessage());
             } else {
                 $this->setError($message);
             }
         }
         return false;
     }
     return $data;
 }
Exemplo n.º 8
0
    /**
     * Loads the validation script for edit form
     *
     * @return void
     */
    protected function loadValidationScript(FOFForm &$form)
    {
        $message = $form->getView()->escape(JText::_('JGLOBAL_VALIDATION_FORM_FAILED'));
        $js = <<<ENDJAVASCRIPT
\t\tJoomla.submitbutton = function(task)
        {
            if (task == 'cancel' || document.formvalidator.isValid(document.id('adminForm'))) {
                Joomla.submitform(task, document.getElementById('adminForm'));
            } else {
                alert('{$message}');
            }
        }
ENDJAVASCRIPT;
        JFactory::getDocument()->addScriptDeclaration($js);
    }
Exemplo n.º 9
0
 /**
  * Renders a FOFForm for a Browse view and returns the corresponding HTML
  *
  * @param   FOFForm   $form      The form to render
  * @param   FOFModel  $model     The model providing our data
  * @param   FOFInput  $input     The input object
  *
  * @return  string    The HTML rendering of the form
  */
 protected function renderFormEdit(FOFForm &$form, FOFModel $model, FOFInput $input)
 {
     // Get the key for this model's table
     $key = $model->getTable()->getKeyName();
     $keyValue = $model->getId();
     $html = '';
     if ($validate = $form->getAttribute('validate')) {
         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('name');
     if (empty($formname)) {
         $formid = 'adminForm';
     }
     $html .= '<form action="index.php" method="post" name="' . $formname . '" id="' . $formid . '"' . $enctype . ' class="form-horizontal' . $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="" />' . 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;
     foreach ($form->getFieldsets() as $fieldset) {
         $fields = $form->getFieldset($fieldset->name);
         if (isset($fieldset->class)) {
             $class = 'class="' . $fieldset->class . '"';
         } else {
             $class = '';
         }
         $html .= "\t" . '<div id="' . $fieldset->name . '" ' . $class . '>' . PHP_EOL;
         if (isset($fieldset->label) && !empty($fieldset->label)) {
             $html .= "\t\t" . '<h3>' . JText::_($fieldset->label) . '</h3>' . PHP_EOL;
         }
         foreach ($fields as $field) {
             $title = $field->title;
             $required = $field->required;
             $labelClass = $field->labelClass;
             $description = $field->description;
             $input = $field->input;
             if (!is_null($title)) {
                 $html .= "\t\t\t" . '<div class="control-group">' . PHP_EOL;
                 $html .= "\t\t\t\t" . '<label class="control-label ' . $labelClass . '" for="' . $field->id . '">' . PHP_EOL;
                 $html .= "\t\t\t\t" . JText::_($title) . PHP_EOL;
                 if ($required) {
                     $html .= ' *';
                 }
                 $html .= "\t\t\t\t" . '</label>' . PHP_EOL;
                 $html .= "\t\t\t\t" . '<div class="controls">' . PHP_EOL;
                 $html .= "\t\t\t\t" . $input . PHP_EOL;
                 if (!empty($description)) {
                     $html .= "\t\t\t\t" . '<span class="help-block">';
                     $html .= JText::_($description) . '</span>' . PHP_EOL;
                 }
                 $html .= "\t\t\t\t" . '</div>' . PHP_EOL;
                 $html .= "\t\t\t" . '</div>' . PHP_EOL;
             } else {
                 $html .= "\t\t\t\t" . $input . PHP_EOL;
             }
         }
         $html .= "\t" . '</div>' . PHP_EOL;
     }
     $html .= '</form>';
     return $html;
 }
Exemplo n.º 10
0
 /**
  * remove a field
  *
  * @param   FOFForm  $form    A form object
  * @param   mixed    $fields  Array of fieldnames or a fieldname
  *
  * @return  void
  */
 private function removeFields($form, $fields)
 {
     $fields = (array) $fields;
     foreach ($fields as $fieldname) {
         $form->removeField($fieldname);
     }
 }
Exemplo n.º 11
0
    /**
     * Renders a label for a fieldset.
     *
     * @param   object  	$field  	The field of the label to render
     * @param   FOFForm   	&$form      The form to render
     * @param 	string		$title		The title of the label
     *
     * @return 	string		The rendered label
     */
    protected function renderFieldsetLabel($field, FOFForm &$form, $title)
    {
        $html = '';
        $labelClass = $field->labelClass ? $field->labelClass : $field->labelclass;
        // Joomla! 2.5/3.x use different case for the same name
        $required = $field->required;
        $tooltip = $form->getFieldAttribute($field->fieldname, 'tooltip', '', $field->group);
        if (!empty($tooltip)) {
            if (version_compare(JVERSION, '3.0', 'ge')) {
                static $loadedTooltipScript = false;
                if (!$loadedTooltipScript) {
                    $js = <<<JS
(function(\$)
{
\t\$(document).ready(function()
\t{
\t\t\$('.fof-tooltip').tooltip({placement: 'top'});
\t});
})(akeeba.jQuery);
JS;
                    $document = FOFPlatform::getInstance()->getDocument();
                    if ($document instanceof JDocument) {
                        $document->addScriptDeclaration($js);
                    }
                    $loadedTooltipScript = true;
                }
                $tooltipText = '<strong>' . JText::_($title) . '</strong><br />' . JText::_($tooltip);
                $html .= "\t\t\t\t" . '<label class="control-label fof-tooltip ' . $labelClass . '" for="' . $field->id . '" title="' . $tooltipText . '" data-toggle="fof-tooltip">';
            } else {
                // Joomla! 2.5 has a conflict with the jQueryUI tooltip, therefore we
                // have to use native Joomla! 2.5 tooltips
                JHtml::_('behavior.tooltip');
                $tooltipText = JText::_($title) . '::' . JText::_($tooltip);
                $html .= "\t\t\t\t" . '<label class="control-label hasTip ' . $labelClass . '" for="' . $field->id . '" title="' . $tooltipText . '" rel="tooltip">';
            }
        } else {
            $html .= "\t\t\t\t" . '<label class="control-label ' . $labelClass . '" for="' . $field->id . '">';
        }
        $html .= JText::_($title);
        if ($required) {
            $html .= ' *';
        }
        $html .= '</label>' . PHP_EOL;
        return $html;
    }