Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Topic started by: pisdoktor on April 21, 2005, 09:09:49 AM

Title: User groups selection on registration
Post by: pisdoktor on April 21, 2005, 09:09:49 AM
is there any way to user select our group on registration?
Title: Re: User groups selection on registration
Post by: Gary on April 21, 2005, 02:14:58 PM
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.
Title: Re: User groups selection on registration
Post by: Oldiesmann on April 21, 2005, 04:55:04 PM
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]'",
Title: Re: User groups selection on registration
Post by: pisdoktor on April 22, 2005, 06:08:47 AM
thanx for useful informations ;) i try to do
Title: Re: User groups selection on registration
Post by: [Unknown] on April 22, 2005, 06:15:20 AM
Oldiesmann, if I created my own form I could join the Administrators (1) group with your modifications.  You have to validate the value.

-[Unknown]
Title: Re: User groups selection on registration
Post by: pisdoktor on April 22, 2005, 12:56:47 PM
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 :(
Title: Re: User groups selection on registration
Post by: Oldiesmann on April 22, 2005, 02:39:18 PM
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.
Title: Re: User groups selection on registration
Post by: pisdoktor on April 22, 2005, 02:55:45 PM
thanx  ;D i will test it...

at the same way can i add gender, location and birthday on registration?
Title: Re: User groups selection on registration
Post by: Oldiesmann on April 22, 2005, 03:28:40 PM
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.
Title: Re: User groups selection on registration
Post by: pisdoktor on April 22, 2005, 08:21:01 PM
thanx Oldiesmann  ;D
Title: Re: User groups selection on registration
Post by: Saku on November 05, 2005, 07:47:57 PM
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

Title: Re: User groups selection on registration
Post by: cfrancesco65 on December 03, 2005, 06:18:18 AM
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
Title: Re: User groups selection on registration
Post by: pisdoktor on December 03, 2005, 10:31:42 PM
Quote from: cfrancesco65 on December 03, 2005, 06:18:18 AM
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 ;)
Title: Re: User groups selection on registration
Post by: jesterhawk on December 06, 2005, 12:39:16 PM
Quote from: Oldiesmann on April 22, 2005, 02:39:18 PM
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
Title: Re: User groups selection on registration
Post by: jesterhawk on December 17, 2005, 04:12:55 PM
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
Title: Re: User groups selection on registration
Post by: jesterhawk on December 17, 2005, 04:14:07 PM
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
Title: Re: User groups selection on registration
Post by: GB on January 19, 2006, 04:31:16 PM
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
Title: Re: User groups selection on registration
Post by: cfrancesco65 on March 29, 2006, 11:47:34 AM
There isn't any news about this topic?!? I'm still waiting... :'(
Title: automatic
Post by: .Darkman on June 05, 2006, 01:38:49 AM
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.