/** * Method to get a form object. * * @param string $name The name of the form. * @param string $source The form source. Can be XML string if file flag is set to false. * @param array $options Optional array of options for the form creation. * @param boolean $clear Optional argument to force load a new form. * @param mixed $xpath An optional xpath to search for the fields. * * @return mixed JForm object on success, False on error. */ protected function loadForm($name, $source = null, $options = array(), $clear = false, $xpath = false) { static $form = null; // Handle the optional arguments. $options['control'] = JArrayHelper::getValue($options, 'control', false); // Create a signature hash. $hash = md5($source . serialize($options)); // Check if we can use a previously loaded form. if (isset($this->_forms[$hash]) && !$clear) { return $this->_forms[$hash]; } // Get the form. RForm::addFormPath(JPATH_COMPONENT . '/models/forms'); RForm::addFieldPath(JPATH_COMPONENT . '/models/fields'); try { $form = RForm::getInstance($name, $source, $options, false, $xpath); if (isset($options['load_data']) && $options['load_data']) { // Get the data for the form. $data = $this->loadFormData(); } else { $data = array(); } // Allow for additional modification of the form, and events to be triggered. // We pass the data because plugins may require it. $this->preprocessForm($form, $data); // Load the data into the form after the plugins have operated. $form->bind($data); } catch (Exception $e) { $this->setError($e->getMessage()); return false; } // Store the form for later. $this->_forms[$hash] = $form; return $form; }
/** * return form object for channel plugin parameters * * @return JForm * * @throws Exception */ public function getPluginParameters() { JPluginHelper::importPlugin('rschannel', $this->getState('plugin')); $data = $this->getItem($this->getState('id')); $xml_path = JPATH_SITE . '/plugins/rschannel/' . $this->getState('plugin') . '/parameters.xml'; if (!file_exists($xml_path)) { throw new Exception('Missing plugin xml file', 404); } $registry = new JRegistry(); $registry->loadString($data->channel_params); $loadData = array('channel_params' => $registry->toArray()); $form = RForm::getInstance('channel_params', $xml_path, array('control' => 'jform')); $form->bind($loadData); return $form; }
<?php echo RForm::label("Region", 'region'); echo RForm::input(array('id' => 'region', 'name' => 'region', 'class' => 'form-control', 'value' => $user->region, 'placeholder' => "region")); echo RForm::label("Mobile", 'mobile'); echo RForm::input(array('id' => 'mobile', 'name' => 'mobile', 'class' => 'form-control', 'value' => $user->mobile, 'placeholder' => "Mobile")); echo RForm::label("QQ", 'qq'); echo RForm::input(array('id' => 'qq', 'name' => 'qq', 'class' => 'form-control', 'value' => $user->qq, 'placeholder' => "QQ")); echo RForm::label("Weibo", 'weibo'); echo RForm::input(array('id' => 'weibo', 'name' => 'weibo', 'class' => 'form-control', 'value' => $user->weibo, 'placeholder' => "Weibo")); echo RForm::label("Homepage", 'homepage'); echo RForm::input(array('id' => 'homepage', 'name' => 'homepage', 'class' => 'form-control', 'value' => $user->homepage, 'placeholder' => "Homepage")); echo RForm::label("Introduction", 'intro'); echo RForm::input(array('id' => 'intro', 'name' => 'intro', 'class' => 'form-control', 'value' => $user->intro, 'placeholder' => "your introduction")); echo RForm::label("Picture"); echo '<br/>'; if ($user->picture) { $picture = RImage::styleSrc($user->picture, User::getPicOptions()); echo RHtml::image($picture, $user->name, array("width" => '120px', 'class' => 'img-thumbnail')); } echo '<br/><br/>'; echo RForm::input(array('type' => 'file', 'name' => 'user_picture', 'accept' => 'image/gif, image/jpeg,image/png')); echo "<br/>"; echo RForm::input(array('type' => 'submit', 'value' => 'Complete', 'class' => "btn btn-lg btn-primary")); echo RForm::endForm(); ?> </div> </div>
/** * Add include paths for model class * * @param boolean $isAdmin Is client admin or site * @param string $optionName Option name * * @return void * * @since 1.3 */ public function addModelIncludePaths($isAdmin, $optionName) { if ($isAdmin) { $this->loadExtensionLanguage($optionName, JPATH_ADMINISTRATOR); $path = JPATH_ADMINISTRATOR . '/components/' . $optionName; RModel::addIncludePath($path . '/models'); JTable::addIncludePath($path . '/tables'); RForm::addFormPath($path . '/models/forms'); RForm::addFieldPath($path . '/models/fields'); } else { $this->loadExtensionLanguage($optionName); $path = JPATH_SITE . '/components/' . $optionName; RModel::addIncludePath($path . '/models'); JTable::addIncludePath($path . '/tables'); JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/' . $optionName . '/tables'); RForm::addFormPath($path . '/models/forms'); RForm::addFieldPath($path . '/models/fields'); } if (!defined('JPATH_COMPONENT')) { define('JPATH_COMPONENT', $path); } }
/** * Loads form for Params field * * @param array $column Content element column * @param RTranslationContentElement $contentElement Content element * @param mixed $data The data expected for the form. * @param string $controlName Name of the form control group * * @return array Array or table with columns columns */ public static function loadParamsForm($column, $contentElement, $data, $controlName = '') { if (version_compare(JVERSION, '3.0', '<') && !empty($column['formname25'])) { $formName = !empty($column['formname']) ? $column['formname25'] : $column['name']; } else { $formName = !empty($column['formname']) ? $column['formname'] : $column['name']; } // Handle the optional arguments. $options = array(); $options['control'] = $controlName; $options['load_data'] = true; $formData = array(); if (!empty($data->{$column['name']})) { $registry = new JRegistry(); $registry->loadString($data->{$column['name']}); $formData[$column['name']] = $registry->toArray(); } // Load common and local language files. $lang = JFactory::getLanguage(); // Load language file $lang->load($contentElement->extension, JPATH_BASE, null, false, false) || $lang->load($contentElement->extension, JPATH_BASE . "/components/" . $contentElement->extension, null, false, false) || $lang->load($contentElement->extension, JPATH_BASE, $lang->getDefault(), false, false) || $lang->load($contentElement->extension, JPATH_BASE . "/components/" . $contentElement->extension, $lang->getDefault(), false, false); // Get the form. RForm::addFormPath(JPATH_BASE . '/components/' . $contentElement->extension . '/models/forms'); RForm::addFormPath(JPATH_BASE . '/administrator/components/' . $contentElement->extension . '/models/forms'); RForm::addFieldPath(JPATH_BASE . '/components/' . $contentElement->extension . '/models/fields'); RForm::addFieldPath(JPATH_BASE . '/administrator/components/' . $contentElement->extension . '/models/fields'); if (!empty($column['formpath'])) { RForm::addFormPath(JPATH_BASE . $column['formpath']); } if (!empty($column['fieldpath'])) { RForm::addFieldPath(JPATH_BASE . $column['fieldpath']); } $xpath = !empty($column['xpath']) ? $column['xpath'] : false; try { $form = RForm::getInstance('com_redcore.params_' . $column['name'] . $controlName, $formName, $options, false, $xpath); // Allow for additional modification of the form, and events to be triggered. // We pass the data because plugins may require it. self::preprocessForm($form, $data, 'content', $column, $contentElement); // Load the data into the form after the plugins have operated. $form->bind($formData); } catch (Exception $e) { return false; } if (empty($form)) { return false; } return $form; }