本文整理汇总了PHP中JForm::setFieldAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP JForm::setFieldAttribute方法的具体用法?PHP JForm::setFieldAttribute怎么用?PHP JForm::setFieldAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JForm
的用法示例。
在下文中一共展示了JForm::setFieldAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: display
/**
* Display the view.
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return mixed A string if successful, otherwise an Error object.
*/
public function display($tpl = null)
{
$this->form = $this->get('Form');
$this->item = $this->get('Item');
$this->state = $this->get('State');
$section = $this->state->get('category.section') ? $this->state->get('category.section') . '.' : '';
$this->canDo = JHelperContent::getActions($this->state->get('category.component'), $section . 'category', $this->item->id);
$this->assoc = $this->get('Assoc');
// Check for errors.
if (count($errors = $this->get('Errors'))) {
JError::raiseError(500, implode("\n", $errors));
return false;
}
// Check for tag type
$this->checkTags = JHelperTags::getTypes('objectList', array($this->state->get('category.extension') . '.category'), true);
JFactory::getApplication()->input->set('hidemainmenu', true);
if ($this->getLayout() == 'modal') {
// If we are forcing a language in modal (used for associations).
if ($forcedLanguage = JFactory::getApplication()->input->get('forcedLanguage', '', 'cmd')) {
// Set the language field to the forcedLanguage and disable changing it.
$this->form->setValue('language', null, $forcedLanguage);
$this->form->setFieldAttribute('language', 'readonly', 'true');
// Only allow to select categories with All language or with the forced language.
$this->form->setFieldAttribute('parent_id', 'language', '*,' . $forcedLanguage);
// Only allow to select tags with All language or with the forced language.
$this->form->setFieldAttribute('tags', 'language', '*,' . $forcedLanguage);
}
} elseif ($this->item->id && $this->form->getValue('language', null, '*') != '*' && JLanguageAssociations::isEnabled() && count($this->item->associations) > 0) {
$this->form->setFieldAttribute('language', 'readonly', 'true');
}
$this->addToolbar();
return parent::display($tpl);
}
示例2: preprocessForm
protected function preprocessForm(\JForm $form, $data, $group = 'content')
{
// if no data, grab the posted form data.
if (!$data instanceof JObject) {
$data = JFactory::getApplication()->input->get('jform', $data, 'array');
$data = JArrayHelper::toObject($data);
}
$params = new JRegistry();
$params->loadArray($data->params);
if ($params->get('discovery.url')) {
$plugin = $params->get('discovery.type');
$language = JFactory::getLanguage();
$language->load('plg_harvest_' . $plugin);
$path = JPATH_ROOT . '/plugins/harvest/' . $plugin . '/forms/harvest.xml';
$form->loadFile($path, false);
foreach (JPluginHelper::getPlugin('ingest') as $plugin) {
$language->load('plg_ingest_' . $plugin->name);
$path = JPATH_ROOT . '/plugins/ingest/' . $plugin->name . '/forms/ingest.xml';
$form->loadFile($path, false);
}
$form->removeField('originating_url');
$form->removeField('harvester');
// hide the run_once value (users cannot set it after discovery)
$form->setFieldAttribute("run_once", 'type', 'hidden');
$form->setFieldAttribute("run_once", 'class', '');
} else {
$form->removeField('state');
$form->removeField('harvested');
$form->removeField('url', 'params.discovery');
$form->removeField('type', 'params.discovery');
}
parent::preprocessForm($form, $data, $group);
}
示例3: display
/**
* Display the view.
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return mixed A string if successful, otherwise an Error object.
*/
public function display($tpl = null)
{
// Initialise variables.
$this->form = $this->get('Form');
$this->item = $this->get('Item');
$this->state = $this->get('State');
// Check for errors.
if (count($errors = $this->get('Errors'))) {
JError::raiseError(500, implode("\n", $errors));
return false;
}
if ($this->getLayout() == 'modal') {
// If we are forcing a language in modal (used for associations).
if ($forcedLanguage = JFactory::getApplication()->input->get('forcedLanguage', '', 'cmd')) {
// Set the language field to the forcedLanguage and disable changing it.
$this->form->setValue('language', null, $forcedLanguage);
$this->form->setFieldAttribute('language', 'readonly', 'true');
// Only allow to select categories with All language or with the forced language.
$this->form->setFieldAttribute('catid', 'language', '*,' . $forcedLanguage);
// Only allow to select tags with All language or with the forced language.
$this->form->setFieldAttribute('tags', 'language', '*,' . $forcedLanguage);
}
} elseif ($this->item->id && $this->form->getValue('language', null, '*') != '*' && JLanguageAssociations::isEnabled() && count($this->item->associations) > 0) {
$this->form->setFieldAttribute('language', 'readonly', 'true');
}
$this->addToolbar();
return parent::display($tpl);
}
示例4: display
/**
* Display the view
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return void
*
* @since 1.6
*/
public function display($tpl = null)
{
$user = JFactory::getUser();
$this->form = $this->get('Form');
$this->item = $this->get('Item');
$this->modules = $this->get('Modules');
$this->levels = $this->get('ViewLevels');
$this->state = $this->get('State');
$this->canDo = JHelperContent::getActions('com_menus', 'menu', (int) $this->state->get('item.menutypeid'));
// Check if we're allowed to edit this item
// No need to check for create, because then the moduletype select is empty
if (!empty($this->item->id) && !$this->canDo->get('core.edit')) {
throw new Exception(JText::_('JERROR_ALERTNOAUTHOR'), 403);
}
// Check for errors.
if (count($errors = $this->get('Errors'))) {
JError::raiseError(500, implode("\n", $errors));
return false;
}
if ($this->getLayout() == 'modal') {
// If we are forcing a language in modal (used for associations).
if ($forcedLanguage = JFactory::getApplication()->input->get('forcedLanguage', '', 'cmd')) {
// Set the language field to the forcedLanguage and disable changing it.
$this->form->setValue('language', null, $forcedLanguage);
$this->form->setFieldAttribute('language', 'readonly', 'true');
// Only allow to select categories with All language or with the forced language.
$this->form->setFieldAttribute('parent_id', 'language', '*,' . $forcedLanguage);
}
} elseif ($this->item->id && $this->form->getValue('language', null, '*') != '*' && JLanguageAssociations::isEnabled() && count($this->item->associations) > 0) {
$this->form->setFieldAttribute('language', 'readonly', 'true');
}
parent::display($tpl);
$this->addToolbar();
}
示例5: onContentPrepareForm
/**
* adds additional fields to the user editing form
*
* @param JForm $form The form to be altered.
* @param mixed $data The associated data for the form.
*
* @return boolean
*
* @since 1.6
*/
public function onContentPrepareForm($form, $data)
{
$version = new JVersion();
if (!$version->isCompatible('3.4')) {
return true;
}
if (!$form instanceof JForm) {
$this->_subject->setError('JERROR_NOT_A_FORM');
return false;
}
// get form name.
$name = $form->getName();
$valid = array('com_content.article', 'com_categories.categorycom_content', 'com_templates.style', 'com_tags.tag', 'com_banners.banner', 'com_contact.contact', 'com_newsfeeds.newsfeed');
// only allow some forms :(
if (!in_array($name, $valid)) {
return true;
}
$config = JFactory::getConfig();
$user = JFactory::getUser();
if ($user->getParam('editor', $config->get('editor')) !== "jce") {
return true;
}
if (!JPluginHelper::getPlugin('editors', 'jce')) {
return true;
}
$link = $this->getLink();
$hasMedia = false;
if ($link) {
$fields = $form->getFieldset();
foreach ($fields as $field) {
$type = $field->getAttribute('type');
if (strtolower($type) === "media") {
$name = $field->getAttribute('name');
$group = (string) $field->group;
$form->setFieldAttribute($name, 'link', $link, $group);
$form->setFieldAttribute($name, 'class', 'input-large wf-media-input', $group);
$hasMedia = true;
}
}
if ($hasMedia) {
// Include jQuery
JHtml::_('jquery.framework');
$document = JFactory::getDocument();
$document->addScriptDeclaration('jQuery(document).ready(function($){$(".wf-media-input").removeAttr("readonly");});');
}
}
return true;
}
示例6: preprocessForm
protected function preprocessForm(JForm $form, $data, $groups = '')
{
$obj = is_array($data) ? JArrayHelper::toObject($data, 'JObject') : $data;
if (isset($obj->alias) && $obj->id > 0) {
$form->setFieldAttribute('type', 'readonly', 'true');
}
parent::preprocessForm($form, $data);
}
示例7: display
/**
* Execute and display a template script.
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return mixed A string if successful, otherwise an Error object.
*
* @since 1.6
*/
public function display($tpl = null)
{
$this->state = $this->get('State');
$this->item = $this->get('Item');
$this->form = $this->get('Form');
// Check for errors.
if (count($errors = $this->get('Errors'))) {
JError::raiseError(500, implode("\n", $errors));
return false;
}
if ($this->getLayout() == 'modal') {
$this->form->setFieldAttribute('language', 'readonly', 'true');
$this->form->setFieldAttribute('catid', 'readonly', 'true');
}
$this->addToolbar();
parent::display($tpl);
}
示例8: onPrepareUserProfileForm
/**
* @param int $userId The user id
* @param JForm $form
*
* @return boolean
*/
function onPrepareUserProfileForm($userId, &$form)
{
// Add the profile fields to the form.
JForm::addFormPath(dirname(__FILE__) . DS . 'profiles');
$form->load('profile', true, false);
// Toggle whether the address1 field is required.
if ($this->params->get('profile-require_address1', 1) > 0) {
$form->setFieldAttribute('address1', 'required', $this->params->get('profile-require_address1') == 2, 'profile');
} else {
$form->removeField('address1', 'profile');
}
// Toggle whether the address2 field is required.
if ($this->params->get('profile-require_address2', 1) > 0) {
$form->setFieldAttribute('address2', 'required', $this->params->get('profile-require_address2') == 2, 'profile');
} else {
$form->removeField('address2', 'profile');
}
// Toggle whether the city field is required.
if ($this->params->get('profile-require_city', 1) > 0) {
$form->setFieldAttribute('city', 'required', $this->params->get('profile-require_address1') == 2, 'profile');
} else {
$form->removeField('city', 'profile');
}
// Toggle whether the region field is required.
if ($this->params->get('profile-require_region', 1) > 0) {
$form->setFieldAttribute('region', 'required', $this->params->get('profile-require_address1') == 2, 'profile');
} else {
$form->removeField('region', 'profile');
}
// Toggle whether the country field is required.
if ($this->params->get('profile-require_country', 1) > 0) {
$form->setFieldAttribute('country', 'required', $this->params->get('profile-require_address1') == 2, 'profile');
} else {
$form->removeField('country', 'profile');
}
// Toggle whether the postal code field is required.
if ($this->params->get('profile-require_postal_code', 1) > 0) {
$form->setFieldAttribute('postal_code', 'required', $this->params->get('profile-require_address1') == 2, 'profile');
} else {
$form->removeField('postal_code', 'profile');
}
// Toggle whether the phone field is required.
if ($this->params->get('profile-require_phone', 1) > 0) {
$form->setFieldAttribute('phone', 'required', $this->params->get('profile-require_address1') == 2, 'profile');
} else {
$form->removeField('phone', 'profile');
}
// Toggle whether the website field is required.
if ($this->params->get('profile-require_website', 1) > 0) {
$form->setFieldAttribute('website', 'required', $this->params->get('profile-require_address1') == 2, 'profile');
} else {
$form->removeField('website', 'profile');
}
return true;
}
示例9: preprocessForm
protected function preprocessForm(JForm $form, $data, $group = 'contact')
{
$userParams = JComponentHelper::getParams('com_contact');
// Deal with captcha
$captcha = $userParams->get('captcha', '0');
if ($captcha === '0') {
$form->removeField('captcha');
} else {
$form->setFieldAttribute('captcha', 'plugin', $captcha);
}
parent::preprocessForm($form, $data, 'user');
}
示例10: preprocessForm
protected function preprocessForm(JForm $form, $data, $group = 'content')
{
$app = JFactory::getApplication();
$params = JComponentHelper::getParams('com_djcatalog2');
$user = JFactory::getUser();
$switchable_fields = array('contact_phone', 'contact_street', 'contact_city', 'contact_zip', 'contact_country', 'contact_company_name', 'contact_email_copy');
foreach ($switchable_fields as $field_name) {
if ($params->get($field_name . '_field', '0') == '0') {
$form->removeField($field_name);
} else {
if ($params->get($field_name . '_field', '0') == '2') {
$form->setFieldAttribute($field_name, 'required', 'required');
$form->setFieldAttribute($field_name, 'class', $form->getFieldAttribute($field_name, 'class') . ' required');
}
}
}
$plugin = JFactory::getApplication()->getParams()->get('contact_captcha', JFactory::getConfig()->get('captcha'));
if ($user->id > 0 || ($plugin === 0 || $plugin === '0' || $plugin === '' || $plugin === null)) {
$form->removeField('captcha');
} else {
$form->setFieldAttribute('captcha', 'plugin', $plugin, 'captcha');
}
}
示例11: display
/**
* Display the view.
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return mixed A string if successful, otherwise an Error object.
*/
public function display($tpl = null)
{
$this->form = $this->get('Form');
$this->item = $this->get('Item');
$this->state = $this->get('State');
$section = $this->state->get('category.section') ? $this->state->get('category.section') . '.' : '';
$this->canDo = JHelperContent::getActions($this->state->get('category.component'), $section . 'category', $this->item->id);
$this->assoc = $this->get('Assoc');
// Check for errors.
if (count($errors = $this->get('Errors'))) {
JError::raiseError(500, implode("\n", $errors));
return false;
}
// Check for tag type
$this->checkTags = JHelperTags::getTypes('objectList', array($this->state->get('category.extension') . '.category'), true);
JFactory::getApplication()->input->set('hidemainmenu', true);
if ($this->getLayout() == 'modal') {
$this->form->setFieldAttribute('language', 'readonly', 'true');
$this->form->setFieldAttribute('parent_id', 'readonly', 'true');
}
$this->addToolbar();
return parent::display($tpl);
}
示例12: display
/**
* Execute and display a template script.
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return mixed A string if successful, otherwise an Error object.
*
* @since 1.6
*/
public function display($tpl = null)
{
if ($this->getLayout() == 'pagebreak') {
// TODO: This is really dogy - should change this one day.
$eName = JFactory::getApplication()->input->getCmd('e_name');
$eName = preg_replace('#[^A-Z0-9\\-\\_\\[\\]]#i', '', $eName);
$this->document->setTitle(JText::_('COM_CONTENT_PAGEBREAK_DOC_TITLE'));
$this->eName =& $eName;
return parent::display($tpl);
}
$this->form = $this->get('Form');
$this->item = $this->get('Item');
$this->state = $this->get('State');
$this->canDo = JHelperContent::getActions('com_content', 'article', $this->item->id);
// Check for errors.
if (count($errors = $this->get('Errors'))) {
JError::raiseError(500, implode("\n", $errors));
return false;
}
if ($this->getLayout() == 'modal') {
// If we are forcing a language in modal (used for associations).
if ($forcedLanguage = JFactory::getApplication()->input->get('forcedLanguage', '', 'cmd')) {
// Set the language field to the forcedLanguage and disable changing it.
$this->form->setValue('language', null, $forcedLanguage);
$this->form->setFieldAttribute('language', 'readonly', 'true');
// Only allow to select categories with All language or with the forced language.
$this->form->setFieldAttribute('catid', 'language', '*,' . $forcedLanguage);
// Only allow to select tags with All language or with the forced language.
$this->form->setFieldAttribute('tags', 'language', '*,' . $forcedLanguage);
}
} elseif ($this->item->id && $this->form->getValue('language', null, '*') != '*' && JLanguageAssociations::isEnabled() && count($this->item->associations) > 0) {
$this->form->setFieldAttribute('language', 'readonly', 'true');
}
$this->addToolbar();
return parent::display($tpl);
}
示例13: edit
/**
* This function displays the newsletter form on the user profile
*
* @param JForm $form - the user form
* @param array $data - the user data
*
* @return bool
*/
public function edit($form, $data)
{
$appl = JFactory::getApplication();
$subscriptionData = CmcHelperUsers::getSubscription($data->email, $this->params->get('listid'));
$renderer = CmcHelperXmlbuilder::getInstance($this->params);
// Render Content
$html = $renderer->build();
if ($appl->isSite()) {
CompojoomHtmlBehavior::jquery();
JHtml::script('media/plg_user_cmc/js/cmc.js');
}
// Inject fields into the form
$form->load($html, false);
if ($subscriptionData) {
$form->setFieldAttribute('newsletter', 'checked', 'checked', 'cmc');
$form->bind(CmcHelperSubscription::convertMergesToFormData($subscriptionData->merges));
}
}
示例14: onContentPrepareForm
function onContentPrepareForm(JForm $form, $data)
{
$name = $form->getName();
if (!in_array($name, array('com_admin.profile', 'com_users.user', 'com_users.profile', 'com_users.registration'))) {
return true;
}
// Add the extra fields
JForm::addFormPath(dirname(__FILE__) . '/profiles');
$form->loadFile('profile', false);
// If we're admin we can do some extra things
if ($name != "com_users.user") {
$form->setFieldAttribute("programmename", "readonly", true, "swg_extras");
// $form->setFieldAttrib("leaderid", "readonly", )
$form->removeField("leaderid", "swg_extras");
$form->removeField("leadersetup", "swg_extras");
}
return true;
}
示例15: preprocessForm
protected function preprocessForm(JForm $form, $data, $group = 'content')
{
$template = $this->getState('template.template');
$lang = JFactory::getLanguage();
$template_path = COM_TZ_PORTFOLIO_PLUS_PATH_SITE . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . $template;
jimport('joomla.filesystem.path');
$formFile = JPath::clean($template_path . DIRECTORY_SEPARATOR . 'template.xml');
// Load the core and/or local language file(s).
$lang->load('tpl_' . $template, $template_path, null, false, true) || $lang->load('tpl_' . $template, $template_path . '/templates/' . $template, null, false, true);
$default_directory = 'components' . DIRECTORY_SEPARATOR . 'com_tz_portfolio_plus' . DIRECTORY_SEPARATOR . 'templates';
$directory = $default_directory . DIRECTORY_SEPARATOR . $template . DIRECTORY_SEPARATOR . 'html';
if (JFolder::exists(JPATH_SITE . DIRECTORY_SEPARATOR . $directory)) {
$form->setFieldAttribute('layout', 'directory', $directory, 'params');
} elseif (is_array($data) && array_key_exists('protected', $data) && $data['protected'] == 1 || is_object($data) && isset($data->protected) && $data->protected == 1) {
$form->removeField('layout', 'params');
} else {
$form->removeField('layout', 'params');
}
if (file_exists($formFile)) {
// Get the template form.
if (!$form->loadFile($formFile, false, '//config')) {
throw new Exception(JText::_('JERROR_LOADFILE_FAILED'));
}
}
// Disable home field if it is default style
if (is_array($data) && array_key_exists('home', $data) && $data['home'] == '1' || is_object($data) && isset($data->home) && $data->home == '1') {
$form->setFieldAttribute('home', 'readonly', 'true');
}
// Attempt to load the xml file.
if (!($xml = simplexml_load_file($formFile))) {
throw new Exception(JText::_('JERROR_LOADFILE_FAILED'));
}
// Get the help data from the XML file if present.
$help = $xml->xpath('/extension/help');
if (!empty($help)) {
$helpKey = trim((string) $help[0]['key']);
$helpURL = trim((string) $help[0]['url']);
$this->helpKey = $helpKey ? $helpKey : $this->helpKey;
$this->helpURL = $helpURL ? $helpURL : $this->helpURL;
}
// Trigger the default form events.
parent::preprocessForm($form, $data, $group);
}