1
votes

I am trying to use JFormFieldUser::getInput as an input to my Joomla forms.

In the backend (logged in with the super user), when I call this method, it produces a nice 'select user' box when clicked displays a list of all users to chose from.

I have been trying to use the User form field on a front end form (logged in with the super user). The result is some what confusing and undesirable. A 'select user' link is produced, but when clicking on it, the result is that the super users, 'User profile' is loaded up: not a list of all users.

Why is this, and how can i make 'select user' show the full list of users like it does in the backend.

4

4 Answers

1
votes

Joomla 3 (from your field definitions):

     <field name="field_name" type="sql" label="COM_FIELD_LABEL"
        sql_select="id,name"
        sql_from="#__users"
        value_field="name"
        key_field="id"
        description="" 
        header="DROP_DOWN_HEADER"
        required="false" />
0
votes

Apparently it can't be done

The JForm (Joomla) User field is the Joomla core field that you can see in Joomla article form to select a user (lightbox with list of user). Becareful this field can not be used on front-end because Joomla core don't manage it on front-end... Often we replace this field on front end with a select dynamic field.

0
votes

I didn't have much luck with this. Instead I created my own component and added in the content from com_users. Worked a treat.

0
votes

Can be done fairly simply but with some significant limitations - depending on your use case.

  • User must be logged in to backend (even if you are trying to access the information frontend). If they are not logged in, it will prompt for log in and break out of the modal :(
  • User must have permissions for User Manager

Then duplicate the \libraries\cms\form\field\user.php to a fields location of your choice (in a modal subdirectory) and rename it to something like user2.php. Make the class name JFormFieldModal_Users2 and the $type='Modal_Users2'.

Don't forget to add the new path to your form .xml if required. The type will be "modal_users2".

Last step. In user2.php, change:

    $link     = 'index.php?option=com_users&amp;view=users&amp;layout=modal&amp;tmpl=component&amp;field=' . $this->id
            . (isset($groups) ? ('&amp;groups=' . base64_encode(json_encode($groups))) : '')
            . (isset($excluded) ? ('&amp;excluded=' . base64_encode(json_encode($excluded))) : '');

to

    $link     = 'administrator/index.php?option=com_users&amp;view=users&amp;layout=modal&amp;tmpl=component&amp;field=' . $this->id
            . (isset($groups) ? ('&amp;groups=' . base64_encode(json_encode($groups))) : '')
            . (isset($excluded) ? ('&amp;excluded=' . base64_encode(json_encode($excluded))) : '');

A bit hacky, but served my purposes.

Less hacky, but less glamorous solution here: The SQL formfield type