First of all you have to install the User Profile module 1.58, that comes with the latest XOOPS version (2.4.5). In older XOOPS versions you can also find this module, but I didn't test it in this older versions, so I can't say it works too.
Then go to the User Profile -> Fields option in the admin area.
In this page you can see all the fields available in the registration forms. On the top left, click in "Add Field".
Then you have to create a form field to let users choose which user profile they are going to register to, for example:
- Students
- Ex-students
- Teachers
We will create a selection using radio buttons for the visitor to choose from, allowing only one choice. Depending on this selection, the user will be added to a specific user group. You have to create this groups beforehand, but that part is easy.
Fill in the form for the new field:
- Title: the name of the field in the form;
- Description: some text to explain the field;
- Category: choose "Default", to be among the first options presented;
- Weight: choose "3", to appear right after the password option in the form;
- Name: give a name to the field value, in this example lets use "user_type". We'll use it later;
- Field Type: choose "radio buttons";
- Field editable from profile: choose only "Administrator";
- Required?: choose "yes";
- Show in registration form: choose "Basic", or the first registration step;
Click on "Submit" button. You'll see a confirmation message and will come back to complete the new field's information. Now you have to add the radio button options.
You we'll see 3 fields for "key" and "value". Follow the example:
- Key:1 Value:Students
- Key:2 Value:Ex-students
- Key:3 Value:Teachers
After filling this, click "Submit". You'll see a confirmation message and will come back again to complete the new field's information. You'll be able to see the options and then you can add more or just finish the edition. Click "Submit" again, you'll see the confirmation message and will go back to the User Profile -> Fields page.
Go to the registration page in your website (http://(your_site)/modules/profile/register.php) to see if your new field is on the right place and with the right options. Correct any mistakes and then we go to the next step, it's not working yet!
In order to use Ghia's suggestion, you have to change the file http://(your_site)/modules/profile/register.php. Make a backup copy of it and open the file in your favorite editor.
Look around the line 266 for this part of code
if ($message) {
Before this line insert this code
if ($profile->getVar('user_type') == 1)//if choice is "student"
{ $member_handler->addUserToGroup(4, $newuser->getVar('uid'));//adduser to group 4-student
}
if ($profile->getVar('user_type') == 2)//if choice is "ex_student"
{ $member_handler->addUserToGroup(5, $newuser->getVar('uid'));//adduser to group 5-ex_student
}
if ($profile->getVar('user_type') == 3)//if choice is "teacher"
{ $member_handler->addUserToGroup(6, $newuser->getVar('uid'));//adduser to group 6-teacher
}
For each condition we are checking the value that was set as the Key, in the field configuration. In the first condition, if the selected option is the first (student) the user will be added to the user group 4, in this case we created a group called "Student" and this user group id is 4.
Upload the register.php file to folder http://(your_site)/modules/profile/ , clear the cache folder and try it.
I'm far from being a PHP expert, so there must be a more elegant way to do it, but I'll let this to the ninja coders to provide it!! This is as far as I can get and it's working for me!
Hope it works for you guys.