[Tutorial] How to add a new field to profile in 2.0.4

This forum is now closed as part of retiring phpBB2.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

This forum is now closed due to phpBB2.0 being retired.
hnam.dev
Registered User
Posts: 2
Joined: Tue Sep 18, 2007 12:55 pm

Re: [Tutorial] How to add a new field to profile in 2.0.4

Post by hnam.dev »

Hi Guys,

First let me say, great tutorial, all of it worked like a charm :)

Now, i'd like to pose the next question... how could I give a simple way to the admin (he is not much into php / db) a possibility to do restrictions on this newly added field.

Let's say we have the new attribute "some_attrib"
I'd like to give a way to the admin to be able to say, no posting rights to users where "some_attrib" is null.
Or even more, if "some_attrib" = "something" then user can access some restricted forum sections...

Any ideas?
sq8
Registered User
Posts: 96
Joined: Thu Sep 06, 2007 7:24 pm

Re: [Tutorial] How to add a new field to profile in 2.0.4

Post by sq8 »

Has this tutorial been updated for 2.0.22 (or something close)? I did a search on the topic and couldn't find a reference to 2.0.22.
User avatar
A_Jelly_Doughnut
Former Team Member
Posts: 34459
Joined: Sat Jan 18, 2003 1:26 am
Location: Where the Rivers Run
Contact:

Re: [Tutorial] How to add a new field to profile in 2.0.4

Post by A_Jelly_Doughnut »

As far as I am aware, this still works on 2.0.22.
A Donut's Blog
"Bach's Prelude (Cello Suite No. 1) is driving Indiana country roads in Autumn" - Ann Kish
User avatar
cmk
Registered User
Posts: 117
Joined: Sun Jun 09, 2002 5:02 pm
Location: Slap bang in the middle of the UK

Re: [Tutorial] How to add a new field to profile in 2.0.4

Post by cmk »

I'm struggling big time with this. I've tried to work through the original post using version 2.0.22 of the forums but alot of the "find" references aren't there. I've mods already installed but I've been to my backups and tried with an un-modded file and it's still the same. Something isn't right somewhere as people are saying this works.

I really need to add new mandatory fields to the registration page (and they appear in the profile too. I was so hoping this would do it but it's just not happening.

Help!! :cry:
"And so, after briefly dipping his toe in the waters of reason, the man with no brain happily retreats to frolic on insanity beach"
User avatar
Ricky_Racer
Registered User
Posts: 609
Joined: Wed Feb 12, 2003 10:02 pm

Re: [Tutorial] How to add a new field to profile in 2.0.4

Post by Ricky_Racer »

Check this post in this topic, it is how I do it. ;)
User avatar
cmk
Registered User
Posts: 117
Joined: Sun Jun 09, 2002 5:02 pm
Location: Slap bang in the middle of the UK

Re: [Tutorial] How to add a new field to profile in 2.0.4

Post by cmk »

Ok this is doing my head in now. I decided to have another go but failed. I took advise from here about making my code search a little less specific but the best I've got now is the field being in the profile but not in the registration screen. As a complete PHP/MySQL novice the following points jumped out at me.

Initially we're told to edit includes/usercp_register.php by looking for

Code: Select all

$strip_var_list = array('username' => 'username', 'email' => 'email', 'icq' => 'icq', 'aim' => 'aim', 'msn' => 'msn', 'yim' => 'yim', 'website' => 'website', 'location' => 'location', 'occupation' => 'occupation', 'interests' => 'interests');
and adding

Code: Select all

'realname' => 'realname',
after

Code: Select all

'username' => 'username', 
This proved difficult given my usercp_register.php file, even before any mods at all,read

Code: Select all

$strip_var_list = array('email' => 'email', 'icq' => 'icq', 'aim' => 'aim', 'msn' => 'msn', 'yim' => 'yim', 'website' => 'website', 'location' => 'location', 'occupation' => 'occupation', 'interests' => 'interests', 'confirm_code' => 'confirm_code');
Thinking back to the less tight search criteria I simply added it thus

Code: Select all

$strip_var_list = array('realname' => 'realname', 'email' => 'email', 'icq' => 'icq', 'aim' => 'aim', 'msn' => 'msn', 'yim' => 'yim', 'website' => 'website', 'location' => 'location', 'occupation' => 'occupation', 'interests' => 'interests', 'confirm_code' => 'confirm_code');
I've no idea if that's right or wrong but it's the only place I can find to make the change.

Another one which totally threw me and became a 'hit and hope' was when told to find

Code: Select all

$template->assign_vars(array(
      'USERNAME' => $username,
I got nothing at all. I searched on

Code: Select all

$template->assign_vars(array(
alone and got a few references with the closest being

Code: Select all

$template->assign_vars(array(
	$template->assign_vars(array(
		'USERNAME' => isset($username) ? $username : '',
		'CUR_PASSWORD' => isset($cur_password) ? $cur_password : '',
		'NEW_PASSWORD' => isset($new_password) ? $new_password : '',
		'PASSWORD_CONFIRM' => isset($password_confirm) ? $password_confirm : '',
		'EMAIL' => isset($email) ? $email : '',
		'CONFIRM_IMG' => $confirm_image, 
but that doesn't have the same criteria for the variables I need to add the real name after. Instead of just adding

Code: Select all

 'REALNAME' => $realname,
I followed the syntax of the section and added the real name reference as follows.

Code: Select all

$template->assign_vars(array(
		'USERNAME' => isset($username) ? $username : '',
		'REALNAME' => isset($realname) ? $realname : '',
		'CUR_PASSWORD' => isset($cur_password) ? $cur_password : '',
		'NEW_PASSWORD' => isset($new_password) ? $new_password : '',
		'PASSWORD_CONFIRM' => isset($password_confirm) ? $password_confirm : '',
		'EMAIL' => isset($email) ? $email : '',
I've no clue if that's right or not (some might say I've no clue at all).

As I've said I'm a complete novice. In the past I've not had to deal with such problems so it's new ground for me. I've no idea if I've done right or wrong. I did notice that some of the spacing was out from the code in the original post which I've tried to line up but I've no idea if that makes any odds at all.

All I do know is I really need this to work so we can go live. Our organisation has its AGM on Monday and I'm being pushed big time for a solution.

There's quite possibly more problems with my changes but short of going through it all again after spending the best part of yesterday afternoon on it I've no real idea. I'm tempted to put my control files back in and start again but part of me is too deflated to even do that.

If anyone want's the changed files to look over then I can send them. That would be a massive help as then I'd have a fighting chance of seeing what changes you'd make and follow the pattern so I can add more fields. One guy asked me to send him my files which I did but I'm a little loathed to keep bugging him about it as that's not fair after being kind enough to offer. I am on a deadline though so have to ask here again unfortunately.

Any help at all would be appreciated.

Please!! :cry:
"And so, after briefly dipping his toe in the waters of reason, the man with no brain happily retreats to frolic on insanity beach"
User avatar
Brf
Support Team Member
Support Team Member
Posts: 53411
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: [Tutorial] How to add a new field to profile in 2.0.4

Post by Brf »

cmk wrote:

Code: Select all

$template->assign_vars(array(
	$template->assign_vars(array(
		'USERNAME' => isset($username) ? $username : '',
		'CUR_PASSWORD' => isset($cur_password) ? $cur_password : '',
		'NEW_PASSWORD' => isset($new_password) ? $new_password : '',
If you have that in your code, you have bigger problems. You can't nest $template calls like that.
User avatar
cmk
Registered User
Posts: 117
Joined: Sun Jun 09, 2002 5:02 pm
Location: Slap bang in the middle of the UK

Re: [Tutorial] How to add a new field to profile in 2.0.4

Post by cmk »

OOPS!!

I've checked the pre modded code and it's

Code: Select all

$template->assign_vars(array(
		'USERNAME' => isset($username) ? $username : '',
		'CUR_PASSWORD' => isset($cur_password) ? $cur_password : '',
		'NEW_PASSWORD' => isset($new_password) ? $new_password : '',
		'PASSWORD_CONFIRM' => isset($password_confirm) ? $password_confirm : '',
		'EMAIL' => isset($email) ? $email : '',
		'CONFIRM_IMG' => $confirm_image, 
The post modded is

Code: Select all

$template->assign_vars(array(
		'USERNAME' => isset($username) ? $username : '',
		'REALNAME' => isset($realname) ? $realname : '',
		'CUR_PASSWORD' => isset($cur_password) ? $cur_password : '',
		'NEW_PASSWORD' => isset($new_password) ? $new_password : '',
		'PASSWORD_CONFIRM' => isset($password_confirm) ? $password_confirm : '',
		'EMAIL' => isset($email) ? $email : '',
		'CONFIRM_IMG' => $confirm_image, 
so it's my copy and paste at fault there.

Sorry for that. :oops:
"And so, after briefly dipping his toe in the waters of reason, the man with no brain happily retreats to frolic on insanity beach"
User avatar
Dragonwolf
Registered User
Posts: 603
Joined: Mon Aug 20, 2007 7:46 pm

Re: [Tutorial] How to add a new field to profile in 2.0.4

Post by Dragonwolf »

I can't seem to get this to work

When I tried it says:

----------------------

Could not update users table

DEBUG MODE

SQL Error : 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'user_realname = '' WHERE user_id = 2' at line 2

(profile code here)

Line : 531
File : usercp_register.php


----------------------


I am using MySQL and have a Linux server.

Also now I seem to have a new user, registered in 1970 and with a blank name, this appeared after I tested the field placed in the admin profile section, which is the only place I have (so far) found it.

Can anyone help?
User avatar
A_Jelly_Doughnut
Former Team Member
Posts: 34459
Joined: Sat Jan 18, 2003 1:26 am
Location: Where the Rivers Run
Contact:

Re: [Tutorial] How to add a new field to profile in 2.0.4

Post by A_Jelly_Doughnut »

Dragonwolf wrote: (profile code here)
Having the full error message (particularly this bit that you omitted) would be helpful :)
A Donut's Blog
"Bach's Prelude (Cello Suite No. 1) is driving Indiana country roads in Autumn" - Ann Kish
User avatar
Dragonwolf
Registered User
Posts: 603
Joined: Mon Aug 20, 2007 7:46 pm

Re: [Tutorial] How to add a new field to profile in 2.0.4

Post by Dragonwolf »

0k

----------------------

Code: Select all

Could not update users table

[b]DEBUG MODE[/b]

SQL Error : 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'user_realname = '' WHERE user_id = 2' at line 2

UPDATE phpbb2_users SET user_email = '(my email)', user_icq = '', user_website = '', user_occ = '', user_from = '', user_interests = '', user_sig = '', user_sig_bbcode_uid = '', user_viewemail = 1, user_aim = '', user_yim = '', user_msnm = '', user_attachsig = 0, user_allowsmile = 1, user_allowhtml = 0, user_allowbbcode = 1, user_allow_viewonline = 1, user_notify = 0, user_notify_pm = 1, user_popup_pm = 1, user_timezone = 0, user_dateformat = 'd M Y h:i a', user_lang = 'english', user_style = 2, user_active = 1, user_actkey = ''user_realname = '' WHERE user_id = 2

Line : 531
File : usercp_register.php
User avatar
dellsystem
Former Team Member
Posts: 3879
Joined: Sat Apr 09, 2005 8:54 pm
Location: Montreal
Name: Wendy
Contact:

Re: [Tutorial] How to add a new field to profile in 2.0.4

Post by dellsystem »

Code: Select all

user_actkey = ''user_realname = ''
looks like it should be

Code: Select all

user_actkey = '', user_realname = ''
Former moderator and website team member | My MODs, and more (GitHub)
User avatar
Dragonwolf
Registered User
Posts: 603
Joined: Mon Aug 20, 2007 7:46 pm

Re: [Tutorial] How to add a new field to profile in 2.0.4

Post by Dragonwolf »

Ah, Thanks a lot (I'm just going to follow all the instructions on the first page through again as I can't find that in the Register code)


BTW, would my database having the prefix "Phpbb2_" effect anything? (I had to create a new one)
User avatar
dellsystem
Former Team Member
Posts: 3879
Joined: Sat Apr 09, 2005 8:54 pm
Location: Montreal
Name: Wendy
Contact:

Re: [Tutorial] How to add a new field to profile in 2.0.4

Post by dellsystem »

Dragonwolf wrote:BTW, would my database having the prefix "Phpbb2_" effect anything? (I had to create a new one)
No, just remember that when you run SQL queries you have to change any instances of phpbb_ (table prefix) to Phpbb2_
Former moderator and website team member | My MODs, and more (GitHub)
User avatar
Dragonwolf
Registered User
Posts: 603
Joined: Mon Aug 20, 2007 7:46 pm

Re: [Tutorial] How to add a new field to profile in 2.0.4

Post by Dragonwolf »

Thanks, I'll try that
Post Reply

Return to “[2.0.x] MOD Writers Discussion”