I'm creating a module for Joomla 3.x and I would like to have a custom parameters. I checked the Creating a custom form field type page on joomla docs and I checked a 3rd party module which has custom fields, but I can't make it work.
Probably I'm missing a step or doing something wrong, but I can't figure out what.
this is what I did so far:
In the modules xml file I added the custom fieldset and field like this:
<fielset name="TITLE" addfieldpath="/modules/mod_mymodule/admin">
<field type="customfield" name="custom" />
</fieldset>
than I created a file called customfield.php and in the file I have this:
<?php
defined('_JEXEC') or die;
jimport('joomla.form.formfield');
class JFormFieldCustomfield extends JFormField {
protected $type = 'customfield';
public function getInput(){
$custom_form = '<div class="input-prepend input-append">';
$custom_form .= '<div class="media-preview add-on"><span title="" class="hasTipPreview"><span class="icon-eye"></span></span></div>';
$custom_form .= '<input type="text" id="jform_params_backgroundimage" class="input-small hasTipImgpath" readonly value="" aria-invalid="false" name="jform[params][backgroundimage]" />';
$custom_form .= '<a rel="{handler: \'iframe\', size: {x: 800, y: 500}}" href="index.php?option=com_media&view=images&tmpl=component&asset=com_modules&author=&fieldid=jform_params_backgroundimage&folder=" title="'.JText::_('JSELECT').'" class="modal btn">'.JText::_('JSELECT').'</a>';
$custom_form .= '<a onclick="jInsertFieldValue('', \'jform_params_backgroundimage\'); return false;" href="#" title="" class="btn hasTooltip" data-original-title="'.JText::_('JCLEAR').'"><span class="icon-remove"></span></a>';
$custom_form .= '</div>';
return $custom_form;
}
}
?>
this is basicly a copy of the media field type, but this is only for testing, obviously I wouldn't need custom field for this.
The fieldset shows up in the admin as a tab as it should be, but the filed doesn't. Than I added the addfilepath to <fields name="params" addfieldpath="/modules/mod_carousel/admin">
as I saw in a 3rd party module, but still nothing.
What am I missing or doing wrong?
only use this code,do not use class
<?php
defined('_JEXEC') or die;
$custom_form = '<div class="input-prepend input-append">';
$custom_form .= '<div class="media-preview add-on"><span title="" class="hasTipPreview"><span class="icon-eye"></span></span></div>';
$custom_form .= '<input type="text" id="jform_params_backgroundimage" class="input-small hasTipImgpath" readonly value="" aria-invalid="false" name="jform[params][backgroundimage]" />';
$custom_form .= '<a rel="{handler: \'iframe\', size: {x: 800, y: 500}}" href="index.php?option=com_media&view=images&tmpl=component&asset=com_modules&author=&fieldid=jform_params_backgroundimage&folder=" title="'.JText::_('JSELECT').'" class="modal btn">'.JText::_('JSELECT').'</a>';
$custom_form .= '<a onclick="jInsertFieldValue('', \'jform_params_backgroundimage\'); return false;" href="#" title="" class="btn hasTooltip" data-original-title="'.JText::_('JCLEAR').'"><span class="icon-remove"></span></a>';
$custom_form .= '</div>';
echo $custom_form;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.