【问题标题】:Joomla 2.5 custom form field typeJoomla 2.5 自定义表单字段类型
【发布时间】:2013-02-13 19:25:02
【问题描述】:

我正在开发 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,我找不到任何“新鲜”的东西)。有人能告诉我我是否需要更多的代码或者这段代码有问题吗?

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

【问题讨论】:

  • 请将自定义字段文件名改为city.php

标签: joomla joomla2.5 joomla-extensions


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-13
      • 2013-01-21
      • 2013-12-28
      • 2012-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-06
      相关资源
      最近更新 更多