Joomla 2.5自定义表单字段类型

时间:2013-02-13 19:25:03

标签: joomla joomla2.5 joomla-extensions

我正在开发Joomla组件,我需要管理区域中的自定义表单字段类型(Joomla 2.5),但我有问题...它只是不起作用。这是我到目前为止所做的:

文件:/administrator/components/com_mycomponent/models/forms/history.xml

<form>

    <fields addfieldpath="/administrator/components/com_mycomponent/models/fields">

        <field
            name="id"
            type="hidden"
            default="0"
            required="true"
            readonly="true"/>                           

        <field 
            id="someid" 
            name="someid" 
            type="City" 
            label="City"
            description="Choose City"
            required="true" />

    </fields>   

</form>

文件:/administrator/components/com_mycomponent/models/fields/history.php

<?php
defined('_JEXEC') or die('Restricted access');

jimport('joomla.form.formfield');

class JFormFieldCity extends JFormField {

        protected $type = 'City';

        // getLabel() left out

        public function getInput() {

            return '<select id="'.$this->id.'" name="'.$this->name.'">  <option value="1">City 1</option> </select>';
        }
}

这就是我改变的一切。我使用本教程:http://docs.joomla.org/Creating_a_custom_form_field_type(适用于Joomla 1.6,我无法找到任何“新鲜”)。有人可以告诉我,我是否需要更多的代码或者这个代码有问题吗?

编辑:我忘了提到这段代码只输出输入字段。

2 个答案:

答案 0 :(得分:2)

似乎该文件应该被命名为city.php,而不是history.php。

答案 1 :(得分:0)

已解决:我使用此功能而非添加自定义表单字段:http://docs.joomla.org/SQL_form_field_type

相关问题