I want to make a module that parses the manufacturers from virtuemart, and the user will select which manufacturers he wants to be shown in the index page. Its the first time I try to create a custom field type.
I created my "custom select list" -the values from the list aren't saved somewhere, so I cant obtain it back.
$fmanuf = $params->get('foreignmanuf');
var_dump($fmanuf); ---> returns NULL
XML:
<fieldset name="brand_params">
<field name="foreignmanuf" type="Manulist" label="Foreign Brands" multiple="true" description="Foreign Cologne Brands" />
</fieldset>
manulist.php:
<?php
defined('JPATH_PLATFORM') or die;
class JFormFieldManulist extends JFormField
{
protected $type = 'Manulist';
protected function getInput()
{
$db= JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('*');
$query->from('#__virtuemart_manufacturers_en_gb');
$db->setQuery($query);
$options = $db->loadObjectList();
$longstring= '<select multiple="multiple">';
$counter=1;
foreach( $options as $row ) {
$longstring .= '<option value="' . $counter . '">'. $row->mf_name . ' </option>' ;
$counter++;
}
$longstring.= '</select>';
return $longstring;
}
protected function getOptions()
{
$options = array();
foreach ($this->element->children() as $option)
{
if ($option->getName() != 'option')
{
continue;
}
$tmp = JHtml::_(
'select.option', (string) $option['value'],
JText::alt(trim((string) $option), preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname)), 'value', 'text',
((string) $option['disabled'] == 'true')
);
$tmp->class = (string) $option['class'];
$tmp->onclick = (string) $option['onclick'];
$options[] = $tmp;
}
reset($options);
return $options;
}
}
I only edited the getInput function, should I somehow edit the getOptions() also ??