0

I want to enhance the user registration form. I want to add a drop-down menu to show usergroups. I already have created a plugin for this and the drop-down is showing.

I have used an XML file to load the usergroup field. However I don't want to show all usergroups.

How can I determine which usergroup are shown in the drop-down box?

Furthermore the value from this standard form usergroup is not saved. How can I save the chosen usergroup?

This is the code:

public function onContentPrepareForm($form, $data)
{
    if ($form->getName() != 'com_users.registration') {
        return;
    }
    $form->loadFile(dirname(FILE) . '/forms/form.xml');
}

and this is the form field in the XML file:

<field name="guest_usergroup" type="usergroup" label="klas" description="klass" multiple="true" />
  • you can create custom field type in joomla,where you can control details to show in drop down field. see-docs.joomla.org/Creating_a_custom_form_field_type – subashbasnet8 Jan 26 '15 at 10:06
  • Please show the code you're currently using – Lodder Jan 26 '15 at 10:09
  • This is de code: public function onContentPrepareForm($form, $data) { if ($form->getName() != 'com_users.registration') { return; } $form->loadFile(dirname(FILE).'/forms/form.xml'); } – Gerard van Hattem Jan 26 '15 at 10:14
  • This is the field from xml-file: <field name="guest_usergroup" type="usergroup" label="klas" description="klass" multiple="true" /> – Gerard van Hattem Jan 26 '15 at 10:18
  • I would suggest you create a custom form field which is a copy of the usergroup form field, then adapt the code according to your needs. That or write a simple database query in your custom form field – Lodder Jan 26 '15 at 12:01
1

You are using existing usergroup field for displaying usergroup dropdown in which there is no option to limit the list of usergroup to display in dropdown list.(Unless you edit the field element)

If you do not want to display all the usergroups then better you should create custom field in which you can filter the usergroups you do not want to display.

On another note, there are many extensions available which can solve your purchase.

Usergroup Selector is one of those extension. Using this plugin you can allow your users to select the usergroup at the time of registration.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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