本文整理汇总了PHP中JForm::getFormControl方法的典型用法代码示例。如果您正苦于以下问题:PHP JForm::getFormControl方法的具体用法?PHP JForm::getFormControl怎么用?PHP JForm::getFormControl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JForm
的用法示例。
在下文中一共展示了JForm::getFormControl方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetFormControl
/**
* Test the JForm::getFormControl method.
*
* @return void
*/
public function testGetFormControl()
{
$form = new JForm('form8ion');
$this->assertThat($form->getFormControl(), $this->equalTo(''), 'Line:' . __LINE__ . ' A form control that has not been specified should return nothing.');
$form = new JForm('form8ion', array('control' => 'jform'));
$this->assertThat($form->getFormControl(), $this->equalTo('jform'), 'Line:' . __LINE__ . ' The form control should agree with the options passed in the constructor.');
}
示例2: setForm
/**
* Method to attach a JForm object to the field.
*
* @param JForm $form The JForm object to attach to the form field.
*
* @return JFormField The form field object so that the method can be used in a chain.
*
* @since 11.1
*/
public function setForm(JForm $form)
{
$this->form = $form;
$this->formControl = $form->getFormControl();
return $this;
}
示例3: onContentPrepareForm
public function onContentPrepareForm(JForm $form, $data)
{
$context = $form->getName();
// Transform categories form name to a valid context
if (strpos($context, 'com_categories.category') !== false) {
$context = str_replace('com_categories.category', '', $context) . '.category';
}
// Extracting the component and section
$parts = $this->getParts($context);
if (!$parts) {
return true;
}
// If we are on the save command we need the actual data
$jformData = JFactory::getApplication()->input->get('jform', array(), 'array');
if ($jformData && !$data) {
$data = $jformData;
}
if (is_array($data)) {
$data = (object) $data;
}
$component = $parts[0];
$section = $parts[1];
$catid = isset($data->catid) ? $data->catid : (isset($data->dpfieldscatid) ? $data->dpfieldscatid : null);
if (!$catid && $form->getField('catid')) {
// Choose the first category available
$xml = new DOMDocument();
$xml->loadHTML($form->getField('catid')->__get('input'));
$options = $xml->getElementsByTagName('option');
if ($firstChoice = $options->item(0)) {
$catid = $firstChoice->getAttribute('value');
$data->dpfieldscatid = $catid;
}
}
// Getting the fields
$fields = DPFieldsHelper::getFields($parts[0] . '.' . $parts[1], $data);
// If there is a catid field we need to reload the page when the catid
// is changed
if ($form->getField('catid') && $parts[0] != 'com_dpfields') {
// The uri to submit to
$uri = clone JUri::getInstance('index.php');
// Removing the catid parameter from the actual url and set it as
// return
$returnUri = clone JUri::getInstance();
$returnUri->setVar('catid', null);
$uri->setVar('return', base64_encode($returnUri->toString()));
// Setting the options
$uri->setVar('option', 'com_dpfields');
$uri->setVar('task', 'field.catchange');
$uri->setVar('context', $parts[0] . '.' . $parts[1]);
$uri->setVar('formcontrol', $form->getFormControl());
$uri->setVar('view', null);
$uri->setVar('layout', null);
// Setting the onchange event to reload the page when the category
// has changed
$form->setFieldAttribute('catid', 'onchange', "categoryHasChanged(this);");
JFactory::getDocument()->addScriptDeclaration("function categoryHasChanged(element){\n\t\t\t\tvar cat = jQuery(element);\n\t\t\t\tif (cat.val() == '" . $catid . "')return;\n\t\t\t\tjQuery('input[name=task]').val('field.catchange');\n\t\t\t\telement.form.action='" . $uri . "';\n\t\t\t\telement.form.submit();\n\t\t\t}\n\t\t\tjQuery( document ).ready(function() {\n\t\t\t\tvar formControl = '#" . $form->getFormControl() . "_catid';\n\t\t\t\tif (!jQuery(formControl).val() != '" . $catid . "'){jQuery(formControl).val('" . $catid . "');}\n\t\t\t});");
}
if (!$fields) {
return true;
}
// Creating the dom
$xml = new DOMDocument('1.0', 'UTF-8');
$fieldsNode = $xml->appendChild(new DOMElement('form'))->appendChild(new DOMElement('fields'));
$fieldsNode->setAttribute('name', 'params');
$fieldsNode->setAttribute('addfieldpath', '/administrator/components/com_dpfields/models/fields');
$fieldsNode->setAttribute('addrulepath', '/administrator/components/com_dpfields/models/rules');
// Defining the field set
$fieldset = $fieldsNode->appendChild(new DOMElement('fieldset'));
$fieldset->setAttribute('name', 'params');
$fieldset->setAttribute('name', 'dpfields');
$fieldset->setAttribute('addfieldpath', '/administrator/components/' . $component . '/models/fields');
$fieldset->setAttribute('addrulepath', '/administrator/components/' . $component . '/models/rules');
$lang = JFactory::getLanguage();
$key = strtoupper($component . '_FIELDS_' . $section . '_LABEL');
if (!$lang->hasKey($key)) {
$key = 'PLG_SYSTEM_DPFIELDS_FIELDS';
}
$fieldset->setAttribute('label', JText::_($key));
$key = strtoupper($component . '_FIELDS_' . $section . '_DESC');
if ($lang->hasKey($key)) {
$fieldset->setAttribute('description', JText::_($key));
}
// Looping trough the fields for that context
foreach ($fields as $field) {
// Creating the XML form data
$type = DPFieldsHelper::loadTypeObject($field->type, $field->context);
if ($type === false) {
continue;
}
try {
// Rendering the type
$node = $type->appendXMLFieldTag($field, $fieldset, $form);
// If the field belongs to a catid but the catid in the data is
// not known, set the required flag to false on any circumstance
if (!$catid && $field->catid) {
$node->setAttribute('required', 'false');
}
} catch (Exception $e) {
JFactory::getApplication()->enqueueMessage($e->getMessage(), 'error');
}
//.........这里部分代码省略.........