如何在模块中创建自定义表单字段类型? [英] How to create a custom form field type in a module?

查看:124
本文介绍了如何在模块中创建自定义表单字段类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用joomla 2.5,并且我想创建一个自定义表单字段类型that stored in the same module.

Im useing joomla 2.5, and I want to create a custom form field type that stored in the same module.

在XML中:

 <fieldset  name="basic" addfieldpath="/modules/mod_royalslider/fields"></fields>
      <fieldset name="basic">
           <field name="title" type="City" label="anythging" description=""   />
      </fieldset>
 </fields>

在文件/modules/mod_royalslider/fields/city.php

<?php
// Check to ensure this file is included in Joomla!
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" >New York</option>'.
                   '<option value="2" >Chicago</option>'.
                   '<option value="3" >San Francisco</option>'.
                   '</select>';
    }
}

现在,如果我删除它,它会向我显示错误 <fieldset name="basic" addfieldpath="/modules/mod_royalslider/fields"></fields>

for now it show me error, when ever i remove <fieldset name="basic" addfieldpath="/modules/mod_royalslider/fields"></fields>

错误消失,该字段显示为文本字段.

the error gone and the field disply as a text field.

推荐答案

您忘记了在addfieldpath

<fields name="params">
   <fieldset name="basic" addfieldpath="/modules/mod_royalslider/models/fields">

       <field name="title" type="City" label="anythging" description=""   />

   </fieldset>
</fields>

只需将fields文件夹放入models文件夹内,然后将路径放在上面即可.

Just put the fields folder inside the models folder and put the path like above.

这篇关于如何在模块中创建自定义表单字段类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆