Invision Community 4: SEO, prepare for v5 and dormant account notifications By Matt Monday at 02:04 PM
Orlando Delcid Posted February 26, 2017 Posted February 26, 2017 Any idea on how i can set a default member group depending on which option they select in Custom Profile Field during registration ? For e,g Registration page -> select box -> server names as values -> selects chicago as the value -> forum assigns him to chicago member group is this possible ?
GriefCode Posted February 26, 2017 Posted February 26, 2017 It should be possible with a hook. So you would require a plugin. There is maybe another solution which I do not know yet
Orlando Delcid Posted February 26, 2017 Author Posted February 26, 2017 @GriefCode Which hook can help me ?
GriefCode Posted February 26, 2017 Posted February 26, 2017 Create a plugin, and hook this class: \IPS\core\modules\front\system\register And then with something like this within your class: /** * @var array */ public static $serverMapping = []; /** * Build Registration Form * * @return \IPS\Helpers\Form */ public static function buildRegistrationForm() { $form = call_user_func_array( 'parent::buildRegistrationForm', func_get_args() ); $servers = array(); foreach(\IPS\Db::i()->select('id, name', 'serverconsole_servers') as $_dbServer) { self::$serverMapping[$_dbServer['id']] = $_dbServer['name']; } $form->add(new \IPS\Helpers\Form\Select('serverconsole_registration_defaultserver',NULL,true, array('options' => self::$serverMapping))); return $form; } /** * Create Member * * @param array $values Values from form * @return \IPS\Member */ public static function _createMember( $values ) { $member = call_user_func_array( 'parent::_createMember', func_get_args() ); if($values['serverconsole_registration_defaultserver']) { $serverName = self::$serverMapping[$values['serverconsole_registration_defaultserver']]; //TODO: override membergroup, maybe with searching server name within the group? } return $member; } You would now only need to define the selection of the member group and set it for the member. You could do that with an ID-Mapping as the groups have unique id's once created and it is only a personal plugin. I recommend you having something to change it later in your accountsettings as exmaple. Maybe it is even more recommend having multiselect and using secondary member groups.
Orlando Delcid Posted February 26, 2017 Author Posted February 26, 2017 9 minutes ago, GriefCode said: Create a plugin, and hook this class: \IPS\core\modules\front\system\register And then with something like this within your class: /** * @var array */ public static $serverMapping = []; /** * Build Registration Form * * @return \IPS\Helpers\Form */ public static function buildRegistrationForm() { $form = call_user_func_array( 'parent::buildRegistrationForm', func_get_args() ); $servers = array(); foreach(\IPS\Db::i()->select('id, name', 'serverconsole_servers') as $_dbServer) { self::$serverMapping[$_dbServer['id']] = $_dbServer['name']; } $form->add(new \IPS\Helpers\Form\Select('serverconsole_registration_defaultserver',NULL,true, array('options' => self::$serverMapping))); return $form; } /** * Create Member * * @param array $values Values from form * @return \IPS\Member */ public static function _createMember( $values ) { $member = call_user_func_array( 'parent::_createMember', func_get_args() ); if($values['serverconsole_registration_defaultserver']) { $serverName = self::$serverMapping[$values['serverconsole_registration_defaultserver']]; //TODO: override membergroup, maybe with searching server name within the group? } return $member; } You would now only need to define the selection of the member group and set it for the member. You could do that with an ID-Mapping as the groups have unique id's once created and it is only a personal plugin. I recommend you having something to change it later in your accountsettings as exmaple. Maybe it is even more recommend having multiselect and using secondary member groups. Lol i have no idea how to get this done :/ i tried using rules application though using custom field and telling it to change class if string A == String B but that doesnt do anything
GriefCode Posted February 26, 2017 Posted February 26, 2017 Just now, Orlando Delcid said: Lol i have no idea how to get this done :/ i tried using rules application though using custom field and telling it to change class if string A == String B but that doesnt do anything Maybe when I got later some time I will create the plugin shortly as it is on 90% done with my given code
Orlando Delcid Posted February 26, 2017 Author Posted February 26, 2017 Oh Great! Got Scared There for a second
GriefCode Posted February 26, 2017 Posted February 26, 2017 Had some trouble getting through it, but here is the plugin:https://dev.grief.network/files/file/3-server-console-register/ I will not place it on the marketplace as I do not think it is something everyone want to use and is in some way special. However, I have a list added to the general application on the marketplace to link these kind of plugins. Sources are as always public:https://github.com/Grief-Code/IPS-Server-Console-RegisterHook Greetings Server Console - Register.xml
Recommended Posts
Archived
This topic is now archived and is closed to further replies.