PDA

View Full Version : Hooks & User Profile field updation


chuanjer
01-18-2008, 05:25 AM
I've written a plugin-script which is triggererd by usercp_complete .it will then update the Profile_status which is 'field6' in vb Userfield.

$userdata =& datamanager_init('User', $vbulletin, ERRTYPE_ARRAY);
$userdata->set_existing($vbulletin->userinfo);
$userdata->set('field6','Yes');
$userdata->pre_save();
if (count($userdata->errors) > 0)
{
// Errors occurred. Do not proceed with the save.
// You may want to loop through $dataman->errors and
// display the results the user.
}
else
{
// No errors occurred.
// Proceed with the save (see the next step).
$userdata->save();
} Keep getting this error:
Fatal error: Field field6 is not defined in $validfields in class vb_datamanager_user in /includes/class_dm.php on line 485Whats wrong with the code?Thanks!

Dismounted
01-18-2008, 05:39 AM
Well, I think the error gives it away. Look in the class file, and look at the error.

chuanjer
01-18-2008, 06:01 AM
I don't think that would help too much coz I cant change any stuff in the core vB PHP codes anyway.And the userfield of interest to me is not a standard vb core field like 'email' or 'referer' so its not set in the class anyway , it was defined by me in the Profile field section of the Admin CP and its named 'field6' by vB.basically what i wanna do is:

Edit the value of field6 in vb table 'usefield' , but I'd like to do so via vB & not by a mysql/php hack.
With this in mind, which Data Manager should I use? admin , user , post ....? :confused:

Thanks

Dismounted
01-18-2008, 06:48 AM
You can add a "validfield" without changing vBulletin core files... Just add to the array.

grant.hayman
02-15-2008, 02:13 PM
Hi Dismounted,

I am trying to do something similar. ( add a value to a profile filed which will be posted (POST method) to register.php

Which array do I need to add to, whats the location of the array?

Thanks

Grant

cheesegrits
02-15-2008, 02:57 PM
chuanjet ... why would you be adding a custom profile field to the User dm in the first place? Custom fields aren't a part of the user dm, as that error message is telling you!

Easiest way would probably be to hang your plugin on the profile_start hook, check if $_POST['do'] is 'updateprofile', and if so poke your field6 value into the $_POST['userfield'] array, something like this:

if ($_POST['do'] == 'updateprofile')
{
$_POST['userfield']['field6'] = "Yes";
$_POST['userfield']['field6_set'] = 1;
}

... and then just let the standard set_userfields() call in the 'updateprofile' processing handle it for you.

-- hugh