View Full Version : Select user profile field inside a user profile field possible?
Amit86
10-25-2012, 09:09 PM
Hello everyone,
I am trying to add a new user profile field.
This user profile field is a 'Single selection menu'
I'd like the menu to contain fields 6 to 15 as a selection
Is that possible?
To make things more realistic,
field6 to 15 are player names my members has in their game-server accounts (it auto fills not editable using some php script)
I'd like for them to be able to choose a main player from the list
TheSupportForum
10-25-2012, 11:22 PM
Hello everyone,
I am trying to add a new user profile field.
This user profile field is a 'Single selection menu'
I'd like the menu to contain fields 6 to 15 as a selection
Is that possible?
To make things more realistic,
field6 to 15 are player names my members has in their game-server accounts (it auto fills not editable using some php script)
I'd like for them to be able to choose a main player from the list
you need to add "Add New Profile Field Category"
then add all the fields to that Category from "6" to "11" as you wish
Amit86
10-25-2012, 11:25 PM
I already have that,
How do i make those fields appear in a Single selection menu userfield so that userfield16 can have one of their selection
--------------- Added 1351249095 at 1351249095 ---------------
Would be glad to get assistance
Amit86
10-27-2012, 09:02 AM
So I take it by the no replies that this isnt possible?
Lynne
10-27-2012, 04:15 PM
Can you post what you have done and tell us what is wrong with your current set up? And, images of what you want always help as I can't picture what you've done and what you want.
Amit86
10-27-2012, 06:21 PM
That's going to be abit long but why not.
I have coded my registration page to require a custom field.
This field is my users username in a game server I am running
In order to make sure they use their username I also added a script that checks if their password match the game password.
This part is working great.
Then, I added a php schedule task that connects to my sql game server and takes all the players info based on the field they used in registration and adding this info into Players user field category (let's say fields 6-15 10 player limit)
You can see this here:
https://vborg.vbsupport.ru/attachment.php?attachmentid=142023&stc=1&d=1351365398
Now, After this is working as it should, I am trying to pull more information but I want the members to be able to set a main player (one of the fields) so I can display other stuff like guild, profession etc
So to do this, I need to add another custom field called Main Player
the members would have to choose from the list of players contained in fields6-15 which one is their main player and this field will be used to pull more information
If the field is already created and you have php code that's setting the other fields, you can set the menu options of your Main Player field like this:
$players = array();
$players[1] = "Rogue";
$players[2] = "Mage";
// etc
$menuid = ID; // Change ID to profile field id of menu
global $vbulletin;
$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "profilefield
SET data = '" . $vbulletin->db->escape_string(serialize($players)) . "'
WHERE profilefieldid = $menuid");
Note that members won't have any value for this field until they set it themselves, unless you also update the userfield table.
John Lester
10-27-2012, 10:41 PM
This field is my users username in a game server I am running
In order to make sure they use their username I also added a script that checks if their password match the game password.
This part is working great.
I sure hope your members know what you are doing. I for one would never register on a site using the same password I use in a game, same name probably depending on the site, but never the pass.
Amit86
10-28-2012, 11:41 AM
If the field is already created and you have php code that's setting the other fields, you can set the menu options of your Main Player field like this:
$players = array();
$players[1] = "Rogue";
$players[2] = "Mage";
// etc
$menuid = ID; // Change ID to profile field id of menu
global $vbulletin;
$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "profilefield
SET data = '" . $vbulletin->db->escape_string(serialize($players)) . "'
WHERE profilefieldid = $menuid");
Note that members won't have any value for this field until they set it themselves, unless you also update the userfield table.
Do i add this in one of the PHP files or can I put it in one of the hook plugins?
If I can use plugins, which hook do you think is best for this?
I sure hope your members know what you are doing. I for one would never register on a site using the same password I use in a game, same name probably depending on the site, but never the pass.
the website makes sure your game account is correct using the password before you LINK your game account, because after LINKING your account you can change things that affect your in-game account..
Reminder, this is a private server not a global server (still not relevant to the case :) )
Do i add this in one of the PHP files or can I put it in one of the hook plugins?
If I can use plugins, which hook do you think is best for this?
Well, in a post above you said:
...I added a php schedule task that connects to my sql game server and takes all the players info based on the field they used in registration and adding this info into Players user field category (let's say fields 6-15 10 player limit)"
So I was thinking that you'd add it as part of that task. But if the users are able to manually edit the list of players then you'd also need to find a hook that's called whenever the profile is updated and do it there as well.
Amit86
10-28-2012, 12:37 PM
fields6 to 15 are not editable and are synced daily with my sql db
i want field 16 to be editable and to have it contain one of the fields from 6~15* (selectable by the member)
OK, so can you add the code I posted above (or something like it) to the code that does your daily syncing?
Amit86
10-28-2012, 02:33 PM
Yeah, but what would be the point there if I want the member itself to choose which one of the players is his main player?
Because that would be the place to have any updates to fields 6-15 be reflected in the menu choices. The user would still need to go to their profile to choose main player.
Maybe I don't understand.
Amit86
10-28-2012, 02:48 PM
Those fields are OK, I am trying to set up field16 to be choosable by the player
I want that field to be a SELECT field, the SELECT options would be the data inside field6(Rogue),field7(Mage),field8(etc),field9,fiel d10,field11,field12,field13,fi eld14,field15 which are not editable by the members..
I do understand that. But now I see that my idea wouldn't work because there is only one set of options in the database for a menu field, and you need each user to have their own, so it probably needs to be built when they go to edit their proifle.
OK, let me look in to that...
OK, I kind of figured it out, but it's not perfect. First create a menu with choices that are just the numbers 1 to 10 (or however many player slots you have). Then create a plugin using hook profile_fetch_profilefields and this code:
$menufield = 16; // id of menu field
$firstplayerfield = 6; // id of first player field
$numplayers = 10;
if ($profilefield['profilefieldid'] == $menufield)
{
global $vbulletin;
$players = array();
for ($i = 0; $i < $numplayers; $i++)
{
$fld = 'field' . ($i + $firstplayerfield);
if (!empty($vbulletin->userinfo[$fld]))
{
$players[$i] = $vbulletin->userinfo[$fld];
if (intval($vbulletin->userinfo['field' . $menufield]) == ($i + 1))
{
$vbulletin->userinfo['field' . $menufield] = $players[$i];
}
}
}
if (count($players))
{
$profilefield['data'] = serialize($players);
}
}
This makes the settings page look OK, but the value being stored in the database is just a number 1-10. And when you go to view a user's profile, that number is displayed (although you get the right menu of choices if it's your profile and you edit the field by clicking the pencil). If you need the player name to be displayed in the profile instead of the number, it can probably be fixed using more plugins (but I don't have time to figure it out right now).
Amit86
10-28-2012, 06:19 PM
Thank you for the kind help,
I have added your code to profile_fetch_profilefields and it works great!
Just need to continue working on this :)
sorry about the attach it was my misstake by reduplicating the plugin
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.