Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Sign In
Not a member yet? Click here to register.

New user field system HOW TO

As you in v6 it is difficult to add new user fields. Thanks to the new modular system in v7 it's now quite simple. No mdifications are required, but in order to add fields you have to create include files, these are stored in the folder includes/user_fields. There is a format to the construct of the filenames:

user_FIELD_include_var.php - carries the database field name & info
user_FIELD_include.php - controls input, display and data validation

If you want to have locale support you can create a file called user_FIELD.php and place it in the folder locale/langauge/user_fieds.

* replace the word field with the name of your field, e.g. user_skype_include_var.php

Lets suppose we're adding a skype field.

1. Create a locale file called user_skype.php which contains the following code:

<?php
// Field Name (appears in edit/profile and user field admin)
$locale['uf_skype'] = "Skype:";
// Description (appears in user field admin)
$locale['uf_skype_desc'] = "Skype Voice Communicator";
?>


2. Create a file called user_skype_include_var.php which contains the following code

<?php
if (!defined("IN_FUSION")) { die("Access Denied"); }

// Field display name
$user_field_name = $locale['uf_skype'];
// Field Description
$user_field_desc = $locale['uf_skype_desc'];
// The name of the database field used to ADD or DROP
$user_field_dbname = "user_skype";
// The group the field appears under; 1 = Contact, 2 = Information, 3 = Options and 4 = Statistics
$user_field_group = 1;
// The database properties used when ADDing the above field
$user_field_dbinfo = "VARCHAR(50) NOT NULL DEFAULT ''";
?>


3. With the admin side of things taken care of, now we need to handle input, display and data validation. Create a file called user_skype_include.php with the following code:

<?php
if (!defined("IN_FUSION")) { die("Access Denied"); }

if ($profile_method == "input") {
// Create the input field for registration and edit profile
echo "<tr>\n";
echo "<td class='tbl'>".$locale['uf_skype'].":</td>\n";
echo "<td class='tbl'><input type='text' name='user_skype' value='".(isset($user_data['user_skype']) ? $user_data['user_skype'] : "")."' maxlength='16' class='textbox' style='width:200px;' /></td>\n";
echo "</tr>\n";
} elseif ($profile_method == "display") {
// Create the display for the user profile
if ($user_data['user_skype']) {
echo "<tr>\n";
echo "<td width='1%' class='tbl1' style='white-space:nowrap'>".$locale['uf_skype']."</td>\n";
echo "<td align='right' class='tbl1'>".$user_data['user_skype']."</td>\n";
echo "</tr>\n";
}
} elseif ($profile_method == "validate_insert") {
// Validate the insert data field & value for our field
$db_fields .= ", user_skype";
$db_values .= ", '".(isset($_POST['user_skype']) ? stripinput(trim($_POST['user_skype'])) : "")."'";
} elseif ($profile_method == "validate_update") {
// Validate the update data value for our field
$db_values .= ", user_skype='".(isset($_POST['user_skype']) ? stripinput(trim($_POST['user_skype'])) : "")."'";
}
?>


Important points
#1 All user_field files must start with same name i.e. user_skype.
#2 The data field and input name must be the same as point #1.
#3 The locale files go in locale/English/user_fields (or whichever language you use).
#4 The 2 include files go in includes/user_fields.

Once you have completed all of the above you should be able to see and enable your new field under Admin => User Fields.

Any questions, please reply to this thread.
Hi Digi

can you tell, how i can make this work, with a must fill out field. before a user can sign up.
Check how the Email Address field is handled.
Ain't it hardcoded?
yep. it is.
Just made my first extra field "adres"!
Not very important, but it was really simple following your steps Digi! :D


I made a little package of it and I wanted to attach so we can use each others user fields but I now see I can't attach B)

Is'nt that a good idea? Make this post into a uge profile-fields database?
Yeah that was perfect, just what I needed. Thanks a lot :)
Would it be possible to make fields required? Also, is it possible to add user field groups?

I am loving the new version 7! It's awesome... great job...

Quote

WEC wrote:
Check how the Email Address field is handled.


So this question was allready answered...
Atm it isn't possible but i can alter it so it can be done, should be in the next rc or final, ok?
TY Digi, I am interested in that aswell. Question, how can we add the user fields on the registration page? And how can we add userfields on custom pages?

Quote

Digitanium wrote:
Atm it isn't possible but i can alter it so it can be done, should be in the next rc or final, ok?


Yep perfect. becores it is a good thing. against spam bots.
Digi, the only thing that I could see this becoming better is an option for Admin added things and User added things.

Some items an Admin only can add, or whoever has access to the members list, and some items that the user can add themselves.
great guide!

Now just wondering how I'd create a group to put them i, rather than be under an exxisting one?
Oh and how to make the fields apear on profile view?
Excellent, this is exactly what I needed for one of my sites. :D

Kudos, Sir Digi
I've reviewed the coding and it will require a bit of extra work, while its too late for v7.00 i will be happy to release a mod shortly after final. most likely it will be part of v7.01. So i've not forgotten and it is on my dev list.
and how about improving this baby like extended profile which muscapaul is updating very lately?

which admins should add fields via admin panel which can be shown from profile, edit profile etcetc..

edit: i didn't know that extended profile is already ported to v7! check www.muscapaul.com to get the mod for v7, Thanks Paul ;) :)
I have one small question about the profile fields. can you have where you can throw raw <div> code into it or does it have to be straight text for the users end?

Quote

Martijn78 wrote:
[quote]WEC wrote:
Check how the Email Address field is handled.


Where do i find this Email Adress field?


Thanx
Thank you for this tutorial, I used it to allow people to add their XBOX Live Gamertag into my database, and then have it pop out their gamercard on their profile.

One thing though, I had to go through and manually create a 'user_FIELD' in my fusion_user and fusion_user_field tables. Was this supposed to be done automatically by the code? Perhaps I have an error some where, no one else mentioned having to manually do this. But...well...maybe it's one of those "you should already have known that" things.
Thread Information
Author
Replies
40 posts
Views
43,586 times
Last Post
Last updated on 3 years ago
You can view all discussion threads in this forum.
You cannot set up a bounty in this discussion thread.
You can start a new discussion thread in this forum.
You cannot reply in this discussion thread.
You cannot start on a poll in this forum.
You cannot upload attachments in this forum.
You can download attachments in this forum.
You cannot up or down-vote on the post in this discussion thread.