How to create your own type of form field in a module?

I am using joomla 2.5 and I want to create a custom form field type that stored in the same module.

In XML:

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

In the file /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>'; } } 

while it shows me an error when I delete <fieldset name="basic" addfieldpath="/modules/mod_royalslider/fields"></fields>

the error disappeared and the field was a field as a text field.

+8
joomla joomla-module
source share
4 answers

You forgot to specify models in addfieldpath

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

Just put the folder folder in the models folder and put the path as above.

+12
source share

You just do this with the code you gave, easily:

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

Use addfieldpath in fields like:

 <fields name="params" addfieldpath="/modules/mod_royalslider/models/fields" > <fieldset name="basic"> <field name="title" type="City" label="anything" description="" /> </fieldset> </fields> 
+1
source share

you can try using this code. this work in the mine

 <fieldset addfieldpath="/modules/mod_royalslider/models/fields" name="basic"> <field name="title" type="City" label="anything" description="" /> </fieldset> 
-one
source share

All Articles