예제 #1
0
 /**
  * Method to retrieve form and field data structure from db
  *
  * @return object containing the data from the database
  * @since		1.6
  */
 public static function getForm(&$params)
 {
     $app = JFactory::getApplication();
     $id = $params->get('catid', 0);
     // Get an instance of the generic visforms model
     $model = JModelLegacy::getInstance('Visforms', 'VisformsModel', array('ignore_request' => true, 'id' => $id));
     $visforms = $model->getForm();
     $fields = $model->getFields();
     $app->setUserState('com_visforms.form' . $visforms->id . '.fields', null);
     $app->setUserState('com_visforms.form' . $visforms->id, null);
     $visforms->fields = $fields;
     $nbFields = count($visforms->fields);
     //get some infos to look whether it's neccessary to add Javascript or special HTML-Code or not
     //variables are set to true if they are true for at least one field
     $required = false;
     $upload = false;
     $textareaRequired = false;
     $hasHTMLEditor = false;
     //helper, used to set focus on first visible field
     $firstControl = true;
     for ($i = 0; $i < $nbFields; $i++) {
         $field = $visforms->fields[$i];
         //set the controll variables
         if (isset($field->attribute_required) && $field->attribute_required == "required") {
             $required = true;
         }
         if (isset($field->typefield) && $field->typefield == "file") {
             $upload = true;
         }
         if (isset($field->textareaRequired) && $field->textareaRequired === true) {
             //we have some work to do to use Javascript to validate that the textarea has content
             $textareaRequired = true;
         }
         if (isset($field->hasHTMLEditor) && $field->hasHTMLEditor == true) {
             $hasHTMLEditor = true;
         }
     }
     //push helper variabels into params
     $params->set('nbFields', $nbFields);
     $params->set('required', $required);
     $params->set('upload', $upload);
     $params->set('textareaRequired', $textareaRequired);
     $params->set('hasHTMLEditor', $hasHTMLEditor);
     $options = array();
     $options['showRequiredAsterix'] = isset($visforms->requiredasterix) ? $visforms->requiredasterix : 1;
     $options['parentFormId'] = 'mod-visform' . $visforms->id;
     //process form layout
     $olayout = VisformsLayout::getInstance($visforms->formlayout, $options);
     if (is_object($olayout)) {
         //add layout specific css
         $olayout->addCss();
     }
     return $visforms;
 }
예제 #2
0
 function display($tpl = null)
 {
     $app = JFactory::getApplication();
     $this->menu_params = $this->get('menuparams');
     $this->visforms = $this->get('Form');
     //check if user access level allows view
     $user = JFactory::getUser();
     $groups = $user->getAuthorisedViewLevels();
     $access = isset($this->visforms->access) && in_array($this->visforms->access, $groups) ? true : false;
     if ($access == false) {
         $app->setUserState('com_visforms.form' . $this->visforms->id . '.fields', null);
         $app->setUserState('com_visforms.form' . $this->visforms->id, null);
         JError::raiseWarning(403, JText::_('JERROR_ALERTNOAUTHOR'));
         return;
     }
     $this->message = $app->getUserState('com_visforms.form' . $this->visforms->id . '.message');
     $fields = $this->get('Fields');
     $app->setUserState('com_visforms.form' . $this->visforms->id . '.fields', null);
     $app->setUserState('com_visforms.form' . $this->visforms->id, null);
     $this->visforms->fields = $fields;
     //Trigger onFormPrepare event
     JPluginHelper::importPlugin('visforms');
     $dispatcher = JDispatcher::getInstance();
     $dispatcher->trigger('onVisformsFormPrepare', array('com_visforms.form', &$this->visforms, &$this->menu_params));
     $this->formLink = "index.php?option=com_visforms&view=visforms&task=send&id=" . $this->visforms->id;
     $document = JFactory::getDocument();
     // Set metadata Description and Keywords - we could use $this->document instead of $document
     if ($this->menu_params->get('menu-meta_description')) {
         $document->setDescription($this->menu_params->get('menu-meta_description'));
     }
     if ($this->menu_params->get('menu-meta_keywords')) {
         $document->setMetadata('keywords', $this->menu_params->get('menu-meta_keywords'));
     }
     $options = array();
     $options['showRequiredAsterix'] = isset($this->visforms->requiredasterix) ? $this->visforms->requiredasterix : 1;
     $options['parentFormId'] = 'visform' . $this->visforms->id;
     //process form layout
     $olayout = VisformsLayout::getInstance($this->visforms->formlayout, $options);
     if (is_object($olayout)) {
         //add layout specific css
         $olayout->addCss();
     }
     parent::display($tpl);
 }