本文整理汇总了PHP中JForm类的典型用法代码示例。如果您正苦于以下问题:PHP JForm类的具体用法?PHP JForm怎么用?PHP JForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JForm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getInput
protected function getInput()
{
$end = $this->element['end'];
$styles = $this->element['styles'];
$background = $this->element['background'] ? 'background-image: url(' . $this->getPathToImages() . '/images/' . $this->element['background'] . ');' : '';
$tag = $this->element['tag'];
if ($end == '1') {
// $html = '</li></'.$tag.'><li>';
$html = '</' . $tag . '><div><div>';
} else {
// $html = '</li><'.$tag.' style="'.$background.$styles.'" ><li>';
$html = '</div></div><' . $tag . ' style="' . $background . $styles . '" >';
}
// var_dump($html);
$identifier = 'menustyles';
$form = new JForm($identifier);
JForm::addFormPath(JPATH_SITE . '/modules/mod_slideshowck/elements/test');
if (!($formexists = $form->loadFile($identifier, false))) {
echo '<p style="color:red">' . JText::_('Problem loading the file : ' . $identifier . '.xml') . '</p>';
return '';
}
$fields = $form->getFieldset();
foreach ($fields as $key => $field) {
// echo '<div class="ckpopup_row">';
$html .= $form->getLabel(str_replace($identifier . "_", "", $key), $identifier);
$html .= $form->getInput(str_replace($identifier . "_", "", $key), $identifier);
// echo '</div>';
}
return $html;
}
示例2: onContentPrepareForm
/**
* Event method that runs on content preparation
*
* @param JForm $form The form object
* @param integer $data The form data
*
* @return bool
*/
public function onContentPrepareForm($form, $data)
{
if (!$form instanceof JForm) {
$this->_subject->setError('JERROR_NOT_A_FORM');
return false;
}
$name = $form->getName();
if (!in_array($name, array('com_content.article'))) {
return true;
}
$include_categories = $this->params->get('include_categories');
if (empty($include_categories)) {
return true;
}
if (empty($data)) {
$input = JFactory::getApplication()->input;
$data = (object) $input->post->get('jform', array(), 'array');
}
if (is_array($data)) {
jimport('joomla.utilities.arrayhelper');
$data = JArrayHelper::toObject($data);
}
if (empty($data->catid)) {
return true;
}
if (!in_array($data->catid, $include_categories)) {
return true;
}
JForm::addFormPath(__DIR__ . '/form');
$form->loadFile('form');
if (!empty($data->id)) {
$data = $this->loadTest($data);
}
return true;
}
示例3: onContentPrepareForm
/**
* Injects several fields into specific forms.
*
* @param JForm $form The form to be altered.
* @param array $data The associated data for the form.
*
* @return boolean
*
* @since 2.0
*/
public function onContentPrepareForm($form, $data)
{
// Check we are manipulating a valid form
if (!$form instanceof JForm) {
$this->_subject->setError('JERROR_NOT_A_FORM');
return false;
}
// Check if the password field needs injecting
if ($this->params->get('use_ldap_password', false) && in_array($form->getName(), $this->passwordForms)) {
// Check if this user should have a profile
if (SHLdapHelper::isUserLdap(isset($data->id) ? $data->id : 0)) {
if ($this->params->get('ldap_password_layout_edit', true)) {
// Check if this is in the 'edit' layout or in the save state
if (strtolower(JFactory::getApplication()->input->get('layout')) === 'edit' || strtolower(JFactory::getApplication()->input->get('task')) === 'save') {
$form->loadFile(realpath(__DIR__) . '/forms/ldap_password.xml', false, false);
}
} else {
$form->loadFile(realpath(__DIR__) . '/forms/ldap_password.xml', false, false);
}
}
}
// Check if the domain field needs injecting
if ($this->params->get('use_ldap_domain', false) && in_array($form->getName(), $this->domainForms)) {
$form->loadFile(realpath(__DIR__) . '/forms/ldap_domain.xml', false, false);
}
return true;
}
示例4: test
/**
* Method to test if the Captcha is correct.
*
* @param SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
* @param Registry $input An optional Registry object with the entire data set to validate against the entire form.
* @param JForm $form The form object for which the field is being tested.
*
* @return boolean True if the value is valid, false otherwise.
*
* @since 2.5
*/
public function test(SimpleXMLElement $element, $value, $group = null, Registry $input = null, JForm $form = null)
{
$app = JFactory::getApplication();
$plugin = $app->get('captcha');
if ($app->isSite()) {
$plugin = $app->getParams()->get('captcha', $plugin);
}
$namespace = $element['namespace'] ?: $form->getName();
// Use 0 for none
if ($plugin === 0 || $plugin === '0') {
return true;
} else {
$captcha = JCaptcha::getInstance((string) $plugin, array('namespace' => (string) $namespace));
}
// Test the value.
if (!$captcha->checkAnswer($value)) {
$error = $captcha->getError();
if ($error instanceof Exception) {
return $error;
} else {
return new JException($error);
}
}
return true;
}
示例5: preprocessForm
/**
* Auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @return void
* @since 3.0
*/
protected function preprocessForm(JForm $form, $data, $group = 'jevents')
{
// Association content items
$app = JFactory::getApplication();
$assoc = false && JLanguageAssociations::isEnabled() && JFactory::getApplication()->isAdmin();
if ($assoc) {
$languages = JLanguageHelper::getLanguages('lang_code');
$addform = new SimpleXMLElement('<form />');
$fields = $addform->addChild('fields');
$fields->addAttribute('name', 'associations');
$fieldset = $fields->addChild('fieldset');
$fieldset->addAttribute('name', 'item_associations');
$fieldset->addAttribute('description', 'COM_JEVENTS_ITEM_ASSOCIATIONS_FIELDSET_DESC');
$add = false;
foreach ($languages as $tag => $language) {
if (empty($data->language) || $tag != $data->language) {
$add = true;
$field = $fieldset->addChild('field');
$field->addAttribute('name', $tag);
$field->addAttribute('type', 'modal_article');
$field->addAttribute('language', $tag);
$field->addAttribute('label', $language->title);
$field->addAttribute('translate_label', 'false');
$field->addAttribute('edit', 'true');
$field->addAttribute('clear', 'true');
}
}
if ($add) {
$form->load($addform, false);
}
}
parent::preprocessForm($form, $data, $group);
}
示例6: preprocessForm
/**
* Method to preprocess the form
*
* @param JForm $form A form object.
* @param mixed $data The data expected for the form.
* @param string $group The name of the plugin group to import (defaults to "content").
*
* @return void
*
* @since 3.2
* @throws Exception if there is an error loading the form.
*/
protected function preprocessForm(JForm $form, $data, $group = 'content')
{
jimport('joomla.filesystem.path');
$lang = JFactory::getLanguage();
$module = $this->getState()->get('module.name');
$basePath = JPATH_BASE;
$formFile = JPath::clean($basePath . '/modules/' . $module . '/' . $module . '.xml');
// Load the core and/or local language file(s).
$lang->load($module, $basePath, null, false, true) || $lang->load($module, $basePath . '/modules/' . $module, null, false, true);
if (file_exists($formFile)) {
// Get the module form.
if (!$form->loadFile($formFile, false, '//config')) {
throw new Exception(JText::_('JERROR_LOADFILE_FAILED'));
}
// Attempt to load the xml file.
if (!($xml = simplexml_load_file($formFile))) {
throw new Exception(JText::_('JERROR_LOADFILE_FAILED'));
}
}
// Load the default advanced params
JForm::addFormPath(JPATH_BASE . '/components/com_config/model/form');
$form->loadFile('modules_advanced', false);
// Trigger the default form events.
parent::preprocessForm($form, $data, $group);
}
示例7: testGetInput
/**
* Test the getInput method.
*
* @return void
*/
public function testGetInput()
{
$form = new JForm('form1');
$this->assertThat($form->load('<form><field name="combo" type="combo" /></form>'), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.');
$field = new JFormFieldCombo($form);
$this->assertThat($field->setup($form->getXml()->field, 'value'), $this->isTrue(), 'Line:' . __LINE__ . ' The setup method should return true.');
}
示例8: onContentPrepareForm
/**
*
* Enter description here ...
* @param JForm $form
* @param unknown $data
*/
function onContentPrepareForm($form, $data)
{
$app = JFactory::getApplication();
$doc = JFactory::getDocument();
$this->template = $this->getTemplateName();
if ($this->template && ($app->isAdmin() && $form->getName() == 'com_templates.style' || $app->isSite() && ($form->getName() == 'com_config.templates' || $form->getName() == 'com_templates.style'))) {
jimport('joomla.filesystem.path');
//JForm::addFormPath( dirname(__FILE__) . DS. 'includes' . DS .'assets' . DS . 'admin' . DS . 'params');
$plg_file = JPath::find(dirname(__FILE__) . DS . 'includes' . DS . 'assets' . DS . 'admin' . DS . 'params', 'template.xml');
$tpl_file = JPath::find(JPATH_ROOT . DS . 'templates' . DS . $this->template, 'templateDetails.xml');
if (!$plg_file) {
return false;
}
if ($tpl_file) {
$form->loadFile($plg_file, false, '//form');
$form->loadFile($tpl_file, false, '//config');
} else {
$form->loadFile($plg_file, false, '//form');
}
if ($app->isSite()) {
$jmstorage_fields = $form->getFieldset('jmstorage');
foreach ($jmstorage_fields as $name => $field) {
$form->removeField($name, 'params');
}
$form->removeField('config', 'params');
}
if ($app->isAdmin()) {
$doc->addStyleDeclaration('#jm-ef3plugin-info, .jm-row > .jm-notice {display: none !important;}');
}
}
}
示例9: testGetInput
/**
* Tests the getInput method.
*
* @return void
*
* @since 3.1
*/
public function testGetInput()
{
$form = new JForm('form1');
$this->assertThat($form->load('<form><field name="moduletag" type="moduletag" label="Module Tag" description="Module Tag listing" /></form>'), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.');
$field = new JFormFieldModuletag($form);
$this->assertThat($field->setup($form->getXml()->field, 'value'), $this->isTrue(), 'Line:' . __LINE__ . ' The setup method should return true.');
$this->assertContains('<option value="nav">nav</option>', $field->input, 'Line:' . __LINE__ . ' The getInput method should return an option with various opening tags, verify nav tag is in list.');
}
示例10: testGetInput
/**
* Test the getInput method.
*
* @return void
*
* @since 11.1
* @todo Should check all the attributes have come in properly.
*/
public function testGetInput()
{
$form = new JForm('form1');
$this->assertThat($form->load('<form><field name="componentlayout" type="componentlayout" extension="com_content" client_id="0" view="blog" /></form>'), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.');
$field = new JFormFieldComponentlayout($form);
$this->assertThat($field->setup($form->getXml()->field, 'value'), $this->isTrue(), 'Line:' . __LINE__ . ' The setup method should return true.');
$this->assertThat(strlen($field->input), $this->greaterThan(0), 'Line:' . __LINE__ . ' The getInput method should return something without error.');
}
示例11: testGetInput
/**
* Test the getInput method.
*
* @return void
*
* @since 11.1
*/
public function testGetInput()
{
$form = new JForm('form1');
$this->assertThat($form->load('<form><field name="accesslevel" type="accesslevel" /></form>'), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.');
$field = new JFormFieldAccessLevel($form);
$this->assertThat($field->setup($form->getXml()->field, 'value'), $this->isTrue(), 'Line:' . __LINE__ . ' The setup method should return true.');
$this->assertThat(strlen($field->input), $this->greaterThan(0), 'Line:' . __LINE__ . ' The getInput method should return something without error.');
}
示例12: testGetInput
/**
* Test the getInput method.
*
* @return void
*
* @since 12.1
*/
public function testGetInput()
{
$form = new JForm('form1');
$this->assertThat($form->load('<form><field name="color" type="color" disabled="true" onchange="window.reload()" class="inputbox" /></form>'), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.');
$field = new JFormFieldColor($form);
$this->assertThat($field->setup($form->getXml()->field, 'value'), $this->isTrue(), 'Line:' . __LINE__ . ' The setup method should return true.');
$this->assertThat(strlen($field->input), $this->greaterThan(0), 'Line:' . __LINE__ . ' The getInput method should return something without error.');
}
示例13: testConstruct
/**
* Tests the JForm::__construct method
*/
public function testConstruct()
{
$form = new JForm('form1');
$this->assertThat($form->load(JFormDataHelper::$loadFieldDocument), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.');
$field = new JFormFieldInspector($form);
$this->assertThat($field instanceof JFormField, $this->isTrue(), 'Line:' . __LINE__ . ' The JFormField constuctor should return a JFormField object.');
$this->assertThat($field->getForm(), $this->identicalTo($form), 'Line:' . __LINE__ . ' The internal form should be identical to the variable passed in the contructor.');
}
示例14: testGetOptions
/**
* Test the getOptions method.
*
* @return void
*
* @since 11.3
*/
public function testGetOptions()
{
$form = new JForm('form1');
$this->assertThat($form->load('<form><field name="radio" type="radio"><option value="0">No</option><item value="1">Yes</item></field></form>'), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.');
$field = new JFormFieldRadio($form);
$this->assertThat($field->setup($form->getXml()->field, 'value'), $this->isTrue(), 'Line:' . __LINE__ . ' The setup method should return true.');
$this->assertThat(strlen($field->input), $this->logicalNot($this->StringContains('Yes')), 'Line:' . __LINE__ . ' The field should not contain a Yes option.');
}
示例15: getInstance
public static function getInstance(JForm $form)
{
if (!array_key_exists($form->getName(), self::$instances)) {
self::$instances[$form->getName()] = new RokSubfieldForm($form);
}
self::$instances[$form->getName()]->updateDataParams();
return self::$instances[$form->getName()];
}