2013-02-13 124 views
1

我正在开发Joomla组件,并且我需要在管理区域中定制表单字段类型(Joomla 2.5),但是我遇到了问题......它只是不起作用。以下是我迄今所做的: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> 

文件:/管理员/组件/ com_mycomponent /模型/场/历史。 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

请将自定义字段文件名改为'city.php'。 – Toretto 2013-02-14 07:34:49

回答

2

好像该文件应该被命名为city.php,不history.php。

相关问题