PDA

View Full Version : Setting custom userfields


squishi
04-22-2011, 09:45 AM
I am in the process of creating an additional registration step to my forum.
I want to set custom userfields in the register_start hook.

Here is what I have:
//some code

$vbulletin->input->clean_array_gpc('r', array(
'userfield' => TYPE_ARRAY,
));

$userdata =& datamanager_init('User', $vbulletin, ERRTYPE_ARRAY);

// set profile fields
$customfields = $userdata->set_userfields($vbulletin->GPC['userfield'], true, 'normal');

//some more code



My problem is that vb checks for required fields. I've tried using the set_userfields method with 'admin', 'normal' or 'register', but the result is the same.

So how do I set custom fields with regex verification (for security) but without checking if fields are required?

kh99
04-22-2011, 01:43 PM
So I'm assuming that the problem is that you only want the regex errors in the error array? Maybe something like:

//some code

function filter_field_errors($params)
{
if ($params[1] == 'required_field_x_missing_or_invalid')
array_pop({$params[0]}->errors);
}

$vbulletin->input->clean_array_gpc('r', array(
'userfield' => TYPE_ARRAY,
));

$userdata =& datamanager_init('User', $vbulletin, ERRTYPE_ARRAY);
$userdata->set_failure_callback('filter_field_errors');

// set profile fields
$customfields = $userdata->set_userfields($vbulletin->GPC['userfield'], true, 'normal');

//some more code


(BTW I haven't tried this at all, even to check for typos).

squishi
04-22-2011, 06:15 PM
I did not know about the possibility of a callback.
Just a minute ago, I found the solution to my problem and came here to report back.
I found it in profile.php.

$userdata->set_existing($vbulletin->userinfo);


Needs to be added after the userdata object is initialized.
That way, I do not run into missing username etc. errors.