Allow users to select user group from custom Joomla login form

 ̄綄美尐妖づ 提交于 2020-01-04 13:05:40

问题


I am developing a website in Joomla 3.0. What I am trying to do is to create a custom login form. The reason I want to do that is to enable users to select the user group they want to be put in while they are registering. So I need to create a dropdown box in the login form. From this dropdown box users would be able to pick up the desired user group. So far I've tried using various plugins and extentions but the problem is that they can't be customized the way I want. So please, if you have any idea how to achieve the result I am looking for share it with me. I guess I will have to try to code it myself, but even in this case I would need a lot of help. Giving me tips and citing good tutorials would also be helpful.
Thank you

PS: If you have solution to my problem for another version of Joomla please share it with me.


回答1:


Probably UsergroupSelector plugin can help you to achieve this. This plugin adds a field in registration form. In case if you do not want to use default html, then you need to add a select box html in your overrided template.




回答2:


The best solution for adding a custom field during the user registration process is probably using a plugin.

You can use a commercial plugin that is available called Multi-Profiles Registration (demo here), that appears to be doing exactly what you want (I have never tested it).

This will cost you some money and save you some time, but I will layout the alternative way, which is developing your own plugin.

Lucky for you, there is an excellent tutorial here, which is actually a chapter form a book called Joomla! Programming (especially page 5 of the tutorial).

Writing a plugin takes time and I will not go over all of the details. The main steps include:

  • Create a plugin configuration file, that will include a list of groups to select from (form element). This is where you (or anyone using the plugin) will select the groups available for registration (groups can be fetched via UsersHelper::getGroups()).
  • Augment the registration form with a select box that includes the desired user groups from the plugin config. This can be done by creating a layout override for your template (templates/<your template>/html/com_users/registration/approval.php) or by injecting it into the document at some phase of the render event by the plugin, which is probably the preferred method if this plugin should be portable.
  • Set the desired group by the plugin by processing the form data and overriding the groups data parameter on the onUserBeforeSave event.


来源:https://stackoverflow.com/questions/18550079/allow-users-to-select-user-group-from-custom-joomla-login-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!