View Full Version : I added a new user field but I'm having trouble
DISLEX
06-11-2008, 07:05 PM
Fixed this issue, new issue below
Opserty
06-11-2008, 07:13 PM
Are you sure $vbulletin is availble at the hook?
You might need to use $this->registry->userinfo['worksafemode']
DISLEX
06-11-2008, 07:14 PM
that might be it, I figured $vbulletin was available everywhere though :)
Is $vbulletin just $this->registry?
MoT3rror
06-11-2008, 07:57 PM
When vB uses a class they put $vbulletin as $this->registry so they don't have to global $vbulletin for each function.
DISLEX
06-11-2008, 08:18 PM
can this cause an issue with cached values?
cause I'm still coding and messing with SQL queries to change the setting (since I don't have a front end to do it yet). And I just forced the field to 0, but it's still catching it and transforming to a URL (meaning it thinks $this->registry...etc is 1, not 0)
Opserty
06-11-2008, 08:35 PM
Not sure what you are on about cache... but $this->registry is just a reference to $vbulletin so they hold the same values.
Use var_dump() to check the values of variables if you need to.
DISLEX
06-11-2008, 08:38 PM
Yeah I figured out the issue, nevermind. But now I have a new one..
I'm trying to add an option for this userfield (a checkbox) on the edit->options page. However I'm running into some strange issues. I'm not completely familiar with it, but I'm essentially copying another plugin. They have a hook on profile_complete, and then they throw in $customfields in there. I've done this, and made a checkbox which shows up, but I have two issues:
1) It's not updating the field correctly. I'm sifting through the PHP and also the templates, and I'm really confused how vB handles custom checkboxes.
2) All the other checkboxes default to unchecked when I have this hook enabled. I have NO idea why, as I'm only changing custom variables and nothing global.
Any ideas?
Opserty
06-11-2008, 08:59 PM
You have to extend the datamanager.
userfield refers to the Custom Profile Fields created in the AdminCP, you've manually altered the database so you need to alter the datamanager.
Find other modifications which do the same and see if you can learn from them. Check the articles section for information about Datamanagers there are articles there. There is also information in the vBulletin manual.
To be honest it would be easier to use the Custom Profile Fields in the AdminCP, then use fieldX in your code e.t.c
DISLEX
06-11-2008, 09:55 PM
You have to extend the datamanager.
userfield refers to the Custom Profile Fields created in the AdminCP, you've manually altered the database so you need to alter the datamanager.
Find other modifications which do the same and see if you can learn from them. Check the articles section for information about Datamanagers there are articles there. There is also information in the vBulletin manual.
To be honest it would be easier to use the Custom Profile Fields in the AdminCP, then use fieldX in your code e.t.c
okay so you're talking about "User Profile Field" in AdminCP? Doesn't that only affect fields in "Edit Profile" and not "Edit Options"? Because I don't see any of the fields added by previous products under that menu option.
Also, this "data manager" you're referring to.. if I add a field to the User Profile Fields in Admin CP, is this altering the data manager like you're saying, or is that a different process?
--------------- Added 1213226533 at 1213226533 ---------------
This example code I'm looking, I just noticed it has another hook for profile_udateoptions, and it checks the variables and uses $userdata->set() to set the variables. I guess that's how it does it...?
--------------- Added 1213228973 at 1213228973 ---------------
Here is my code for profile_complete
if($_REQUEST['do'] == 'editoptions') {
// MODE
$profilefieldname = 'worksafemode';
$mykey = 1;
$myval = "Enable worksafe mode";
$custom = "";
$customfields['login'] .= "<fieldset class='fieldset'><legend>Worksafe Mode</legend>";
$customfields['login'] .= '<table cellpadding="0" cellspacing="3" border="0" width="100%">
<tr>
<td>
Check this box if you wish to enable worksafe mode, which enables worksafe-related features<br />
</td>
</tr>
<tr>';
$mychecked= $vbulletin->userinfo['worksafemode'] ? 'checked="checked"' : '';
$custom .= '<td valign="top"><label for="cb_cpf_'.$profilefieldname.'_'.$mykey.'"><input type="checkbox" name="userfield['.$profilefieldname.'][]" value="'.$mykey.'" id="cb_cpf_'.$profilefieldname.'_'.$mykey.'" '.$mychecked.' />'.$myval.'</label></td>';
$customfields['login'] .= $custom;
$customfields['login'] .= "</tr></table></fieldset>";
}
profile_updateoptions
$wsmode = intval($vbulletin->GPC['userfield']['worksafemode']);
$userdata->validfields['worksafemode'] = array(TYPE_NOCLEAN, REQ_NO);
$userdata->set('worksafemode' $wsmode, false);
I just tried to copy another plugin and this is the best I could come up with, hehe
Dismounted
06-12-2008, 05:49 AM
okay so you're talking about "User Profile Field" in AdminCP? Doesn't that only affect fields in "Edit Profile" and not "Edit Options"? Because I don't see any of the fields added by previous products under that menu option.
You can choose where to put them. Fields will not show in the Admin CP if they were not added via the Admin CP method.
DISLEX
06-12-2008, 06:01 AM
Any ideas what's wrong with my code? Another plugin is essentially doing the same thing, but with text/select fields rather than a single checkbox...
I can't get the value to store when you click save, though.
Opserty
06-12-2008, 09:13 AM
Just use "User Profile fields" vBulletin will then handle all the saving and editing and management of the front-end. It will save you a load of trouble.
You'd typically only be extending the user table if you are releasing a modification, to save modification users the trouble of creating the field. Otherwise it is far easier to stick to User Profile Fields.
(The code you posted looks fine but I haven't messed about much with 3.7.x so I'm not sure how it is changed if at all.)
DISLEX
06-12-2008, 03:22 PM
Yeah, I'll probably end up doing it through the admin cp, but I also want to familiarize myself with vbulletin, so I'd really like to figure out what I did wrong in the code :)
Opserty
06-12-2008, 03:29 PM
It is always best to start out simple when you are learning.
For example just adding a code manually through the datamanger via. PHP then work onto submitting forms, using hooks, e.t.c. (instead of diving in at the deep end).
DISLEX
06-12-2008, 04:01 PM
I couldn't find a great tutorial or article on what I was trying to do - add a user field manually (instead of via Admin CP). The two datamanager articles I found didn't seem to really apply to me either. Can you help point me in the right direction?
Opserty
06-12-2008, 04:13 PM
<a href="http://www.vbulletin.com/docs/html/data_managers" target="_blank">Data Managers</a> (Check the "Advanced Datamanager Techniques" section it has something on modification via. Plugins)
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.