joomla3.0 - Joomla 3.1.x 中的自定义字段

标签 joomla3.0 joomla3.1

我需要在 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" />

最佳答案

您将在此处找到一个示例,您可以遵循该示例并进行调整以满足您的需求:

  1. 在“administrator/components/your_component/models/”目录中,创建(如果不存在)目录和文件“fields/totalprice.php”

  2. 在“totalprice.php”文件中放置您将在下面找到的示例代码,并根据您的需求进行编码。

  3. 在“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/

相关文章:

php - 连接多个表时,Ajax 不调用 php 查询

security - Joomla砍死了。怎么预防?

javascript - JSON - 传递表单输入值作为 json 字符串出错

php - Joomla 升级数据库错误从 v3.1.1 到 3.1.5

joomla - 在 Joomla Controller 中注册任务

php - 如何使 Joomla 3.0 富文本编辑器允许 HTML?

php - Joomla K2 额外字段 : Differentiated Display

css - joomla 3-别名使无法连接CSS

Joomla 获取自定义父类别的子类别

joomla - 在 Joomla 3 中添加快捷图标