Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Thema gestartet von: pisdoktor in April 21, 2005, 09:09:49 VORMITTAG

Titel: User groups selection on registration
Beitrag von: pisdoktor in April 21, 2005, 09:09:49 VORMITTAG
is there any way to user select our group on registration?
Titel: Re: User groups selection on registration
Beitrag von: Gary in April 21, 2005, 02:14:58 NACHMITTAGS
In my opinion I dont think that would be pretty smart. If user's could select the group at regestration, they could chose Administrator and totally screw your forum up.
Titel: Re: User groups selection on registration
Beitrag von: Oldiesmann in April 21, 2005, 04:55:04 NACHMITTAGS
Gaz - you would specify which group(s) a user could join. You wouldn't give them access to every membergroup on the board.

pis - this is actually relatively easy to do. The main issue here is whether you want the selected group to be a primary group (like Administrator, Global Moderator, Support Specialist, etc.) or a secondary group (where they would get all the permissions that the group gives them, but the group name would not be displayed any place and they wouldn't get special stars for being in that group).

First, you need to get the name and ID_GROUP value for each group you want them to be able to choose from. This can be done by hovering your mouse over the "modify" link next to each group in the "manage membergroups" section of your admin center and looking at the value of "id" in the URL.

In Register.template.php

Find
</tr><tr>
<td width="40%">
<b>', $txt[82], ':</b>
</td>
<td>
<input type="password" name="passwrd2" size="30" />
</td>
</tr>


Add after that
<tr>
<td width="40%">
<b>Group:</b>
</td>
<td>
<select name="group" size="30">
<option value="{group_id}">Group Name</option>
<option value="{group_2_id}">Group 2 Name</option>
...
</select>
</td>
</tr>


In Sources/Register.php:

If you want that to be a regular group:

Find
if ($user_info['is_admin'])
$register_vars['ID_GROUP'] = empty($_POST['group']) ? 0 : (int) $_POST['group'];


Replace
$register_vars['ID_GROUP'] = empty($_POST['group']) ? 0 : (int) $_POST['group'];

Or, if you want that to be an "additional" group:

Find
'ID_POST_GROUP' => 4,

Add after that
'additionalGroups' => "'$_POST[group]'",
Titel: Re: User groups selection on registration
Beitrag von: pisdoktor in April 22, 2005, 06:08:47 VORMITTAG
thanx for useful informations ;) i try to do
Titel: Re: User groups selection on registration
Beitrag von: [Unknown] in April 22, 2005, 06:15:20 VORMITTAG
Oldiesmann, if I created my own form I could join the Administrators (1) group with your modifications.  You have to validate the value.

-[Unknown]
Titel: Re: User groups selection on registration
Beitrag von: pisdoktor in April 22, 2005, 12:56:47 NACHMITTAGS
Oldiesmann thanx for your help ;) now another question,

how do i can show user groups automatically? i can not add a new group in register.template.php everytime :(
Titel: Re: User groups selection on registration
Beitrag von: Oldiesmann in April 22, 2005, 02:39:18 NACHMITTAGS
Didn't think about that [Unknown]...

pis - modify the code I gave you above as follows:

Find
$register_vars['ID_GROUP'] = empty($_POST['group']) ? 0 : (int) $_POST['group'];

Replace
if($_POST['group'] == 1 && !$context['user']['is_admin'])
{
    $register_vars['ID_GROUP'] = 0;
}
else
{
    $register_vars['ID_GROUP'] = empty($_POST['group']) ? 0 : (int) $_POST['group'];
}


That will prevent anyone from making themselves admins :)

As far as automatically getting groups:

Add this to the register function in Register.php, right after the first "global" line:

$query = db_query("SELECT ID_GROUP, groupName FROM {$db_prefix}membergroups WHERE minPosts = '-1'", __FILE__, __LINE__);
$myarray = mysql_fetch_assoc($query);
foreach($myarray AS $group)
{
    // These are all the groups we don't want them to join (admin, global mod, moderator, etc.)
    if(in_array($myarray['ID_GROUP'], array('1', '2', '3'))
        continue;
    $context['groupstuff'] = array('ID' => $group['ID_GROUP'], 'name' => $group['groupName'],);
}
mysql_free_result($query);


Then, modify the code in Register.template.php as follows

Instead of manually typing a new line for each group, you could do something like this

<option value="', $context['groupstuff']['ID'], '">', $context['groupstuff']['name'], '</option>

I think that will work, but you might want to test it first to make sure.
Titel: Re: User groups selection on registration
Beitrag von: pisdoktor in April 22, 2005, 02:55:45 NACHMITTAGS
thanx  ;D i will test it...

at the same way can i add gender, location and birthday on registration?
Titel: Re: User groups selection on registration
Beitrag von: Oldiesmann in April 22, 2005, 03:28:40 NACHMITTAGS
Yeah. Take a look at Register.php for more details. The only problem with birthdate though is the way its done - SMF has you input the month, day and year seperately, but it is stored as one value. You will probably want to copy the birthday validation stuff from Profile.php to handle that.
Titel: Re: User groups selection on registration
Beitrag von: pisdoktor in April 22, 2005, 08:21:01 NACHMITTAGS
thanx Oldiesmann  ;D
Titel: Re: User groups selection on registration
Beitrag von: Saku in November 05, 2005, 07:47:57 NACHMITTAGS
i have SMF 1.1 RC1 and i just replace this line

'ID_POST_GROUP' => 4,

by

'ID_GROUP' => X,

where X is the ID of the Regular group where i want the new members to be

Titel: Re: User groups selection on registration
Beitrag von: cfrancesco65 in Dezember 03, 2005, 06:18:18 VORMITTAG
How can I do the same with SMF 1.1?!? I take a look to Register.php but it seems to be quite different from 1.05 version...

Thanx
Titel: Re: User groups selection on registration
Beitrag von: pisdoktor in Dezember 03, 2005, 10:31:42 NACHMITTAGS
Zitat von: cfrancesco65 in Dezember 03, 2005, 06:18:18 VORMITTAG
How can I do the same with SMF 1.1?!? I take a look to Register.php but it seems to be quite different from 1.05 version...

Thanx

i have same trouble! i use smf 1.1 RC1 and i take a look register.php but i cant see anything to change...

Edit: i want to add gender and birthday info on registration ;)
Titel: Re: User groups selection on registration
Beitrag von: jesterhawk in Dezember 06, 2005, 12:39:16 NACHMITTAGS
Zitat von: Oldiesmann in April 22, 2005, 02:39:18 NACHMITTAGS
Then, modify the code in Register.template.php as follows

Instead of manually typing a new line for each group, you could do something like this

<option value="', $context['groupstuff']['ID'], '">', $context['groupstuff']['name'], '</option>
Ok, I am new to the HTML/PHP coding, but trying to learn quick.  Where do I put this or how do I do this?  Please give me a little more info.

Thanks,
JH
Titel: Re: User groups selection on registration
Beitrag von: jesterhawk in Dezember 17, 2005, 04:12:55 NACHMITTAGS
I hate to post this to bump this back up, but does anyone have an answer to my question just above this post?

Thanks,
JH
Titel: Re: User groups selection on registration
Beitrag von: jesterhawk in Dezember 17, 2005, 04:14:07 NACHMITTAGS
Also, is there anyway that this could be made into a mod that someone not as skilled as PHP and HTML could install? That would also help when upgrades come out to keep everything working.

Thanks,
JH
Titel: Re: User groups selection on registration
Beitrag von: GB in Januar 19, 2006, 04:31:16 NACHMITTAGS
I agree - I am sitting with the same problem.

Oldiesmann -

Thanks for your help. Is there a way to give a user to select multiple groups when signing up. I would like to give the user a range a choice of groups to join with a checkbox next to each choice.

Thanks

Guy
Titel: Re: User groups selection on registration
Beitrag von: cfrancesco65 in März 29, 2006, 11:47:34 VORMITTAG
There isn't any news about this topic?!? I'm still waiting... :'(
Titel: automatic
Beitrag von: .Darkman in Juni 05, 2006, 01:38:49 VORMITTAG
i want the new users to be automatically classified into groups.
For example
the first member will be BLUE group
second will be GREEN group
third will be again BLUE group and so on...

Is there any way.