我需要在 Joomla 3.1 中创建一个新的自定义字段。但你做不到。我遇到了一些关于在 Joomla 2.5 中创建自定义表单的文章,但在这个新版本中我不能。
任何人都会帮助我,我需要在 joomla 3.1 的文章后端而不是 joomla 2.5 中创建自定义字段。
在这种情况下,我需要在后端 joomla 文章中创建。
<field name="totalprice" type="text" label="COM_CONTENT_TOTAL_PRICE_LABEL" description="COM_CONTENT_TOTAL_PRICE_DESC" class="input-xlarge" size="30" required="true" labelclass="control-label" />
最佳答案
您将在此处找到一个示例,您可以遵循该示例并进行调整以满足您的需求:
在“administrator/components/your_component/models/”目录中,创建(如果不存在)目录和文件“fields/totalprice.php”
在“totalprice.php”文件中放置您将在下面找到的示例代码,并根据您的需求进行编码。
在“models/forms/”目录中,找到将调用来构建表单的 xml 文件,然后创建自定义字段,例如:
<field name="totalprice" type="text" label="COM_CONTENT_TOTAL_PRICE_LABEL" description="COM_CONTENT_TOTAL_PRICE_DESC" class="input-xlarge" size="30" required="true" labelclass="control-label" />
totalprice.php 文件的代码示例
<?php
defined('_JEXEC') or die('Direct Access to this location is not allowed.');
//defined('JPATH_BASE') or die; TODO CHECK THIS
jimport('joomla.form.formfield');
/**
* Created by custom field class
*/
class JFormFieldTotalPrice extends JFormField
{
/**
* The form field type.
* @access protected
* @var string
*/
protected $type = 'totalprice';
/**
* Method to get the field input markup.
* @access protected
* @return string The field input markup.
*/
protected function getInput()
{
// Initialize variables.
$html = array();
//Load user example. REPLACE WITH YOU CODE
$html[] = '<input type="text" name="totalprice" value="' . $your_data->value . '" />';
return implode($html);
}
}
?>
关于joomla3.0 - Joomla 3.1.x 中的自定义字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19412630/