PDA

View Full Version : Configuring a new field via usercp (user)


mfyvie
06-21-2007, 09:08 PM
I'm having a bit of trouble.

I'm writing a mod where I'd like to alter a new field in the user table via the edit user page of the admincp.

I added the relevant phrases and then added this to the useradmin_edit_column2 hook:

print_table_break('', $INNERTABLEWIDTH);
print_table_header($vbphrase['ae_header']);
print_yes_no_row($vbphrase['ae_user_exempt_option'], 'user[mloginexempt]', $user['mloginexempt']);

This seems to work fine - it reads the value from the database, however the problem comes when I hit the "save" button. I get the following message:

Fatal error: Field mloginexempt is not defined in $validfields in class vb_datamanager_user in /includes/class_dm.php on line 485

I've looked for somewhere to add this new variable, but so far I can't find it.

I tried adding this to useradmin_edit_start:

$user = array_merge($user, array('mloginexempt' => 0));

But this just had the effect of always reporting this option as "no", regardless of what the database said.

Does anyone know what the missing piece of code might be, and the hook where I should place it?

This could be useful for anyone else who tries to add an additional option to the edit user function of the admincp.

Mark

mfyvie
06-23-2007, 08:14 PM
Anyone? This isn't really an obvious question, so was hoping someone with a bit more experience might be able to shed some light on this...

mfyvie
06-30-2007, 11:13 AM
Finally managed to solve this, and thought I'd share this here for anybody else who tries the same thing.

After several hours of sifting through tutorials, I found this one about adding bitfields (https://vborg.vbsupport.ru/showthread.php?t=116155).

I read through it and eventually figured out that I could adapt it to non-bitfield options. Therefore all I was missing was this code:

if (!isset($this->validfields['mloginexempt']))
{
$this->validfields['mloginexempt'] = array(TYPE_BOOLEAN, REQ_NO);
}
Which I inserted at the userdata_data hook.

Yes, I know, I probably should have used a bitfield for this, but I'm just adding this on at the end. I'll know better for next time :)

Michael Biddle
06-30-2007, 02:51 PM
In plugin: forumdata_start put this code in it to make a valid field.

$this->validfields['mloginexempt'] = array(TYPE_BOOLEAN, REQ_NO);

mfyvie
06-30-2007, 03:03 PM
In plugin: forumdata_start put this code in it to make a valid field.

$this->validfields['mloginexempt'] = array(TYPE_BOOLEAN, REQ_NO);

Would I be doing that if I wanted to make use of it in all pages? At the moment I only need it when updating the record in the admincp. The other sections of the mod read the value directly from the DB (as part of a larger query).

Will changing it as you indicate also mean that it will work both in the admincp and could be read anywhere else?