0

I'm facing a strange problem. I'm trying to define a custom field for the frontend-view of my component like this:

defined('JPATH_BASE') or die;

jimport('joomla.form.formfield');
jimport('joomla.form.helper');
JFormHelper::loadFieldClass('list');

class JFormFieldAssignToUser extends JFormFieldList
{
    protected $type = 'assigntouser';

    protected function getInput() 
    {
        $html                 =     array();
        $user                 =     JFactory::getUser();

        $html[]             =     JHtml::_('select.option', 
                                "Test", 
                                "Test");

        $html                 =     array_merge(parent::getOptions(), $html);

        return $html;
    }
}

now I'm adding this to my xml:

<field    name            =        "assigntouser" 
        type            =        "assigntouser"    
        label            =        "TEST"                
        description        =        "TEST"
        filter            =        "safehtml"
        default            =        "">
            <option value    =    "">TEST</option>
</field>

and include it to my layout like that:

<?php echo $this->form->renderFieldset("testfieldset"); ?>

But it only shows this error:

Notice: Array to string conversion in /var/www/web1/htdocs/layouts/joomla/form/renderfield.php on line 35

A field, which is designed in the same way, that is added to the backend of Joomla, works without problems...

3

I think you want to use use getOptions(..) not getInput(...) with a JFormFieldList.

getInput returns the full <select /> input as a string. getOptions populates the select options with an array of <option /> strings.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.