Create a Joomla! registration form with dynamic user group assignment
The RSForm!Pro Joomla! User Registration plugin allows you to create an user registration form, while the person who submits the form eventually ends up within the default Registered user group). Due to the RSForm!Pro's flexible nature, you can implement a dynamic user group assignment. Within the following example a dropdown field will dictate the user group.
1. Preparation
- Setup your form as explained in the RSForm!Pro Joomla! User Registration plugin documentation.
- Add an additional form element that is used to select the destination group. In this case we will use a dropdown with either of the following configuration:
- setup your dropdown items using the pipeline "|". You can find the groups IDs from backend > Users > Groups.
3|Author 4|Editor 6|Manager 5|Publisher 2|Registered
2. Script
The following script is added within "Script called after form has been processed" area (backend > Components > RSForm!Pro > Manage Forms > your form > Properties > PHP Scripts):
Replace my-dropdown-name-here with your dropdown exact name.
list($replace, $with) = RSFormProHelper::getReplacements($SubmissionId); $userID = str_replace($replace, $with, '{global:userid}'); Joomla\CMS\User\UserHelper::setUserGroups($userID, $_POST['form']['my-dropdown-name-here']);When the form is submitted, the user will have the group that was selected in the dropdown.
Tip:
You can assign multiple user groups, by simply setting your dropdown type to allow multiple selections (edit the dropdown > Attributes > and set 'Multiple' to 'Yes').
19 persons found this article helpful.
You Should Also Read
Plugin - Joomla! User Registration (Create custom user registration forms) HOT |
Unique registration number HOT |