Rev 831 | Blame | Last modification | View Log | RSS feed
Creating custom fields for user profiles========================================*** THIS DOCUMENT IS UNDER DEVELOPMENT, SO IT'S NOT YET COMPLETE ***This documents describes how you can create your own custom fieldswithin the profiles of Phorum users.Table of contents:1. Introduction2. Creating the custom field3. Using the custom field3.1 From the registration process3.2 From the user's control center3.3 From a module1. Introduction-------------------------------------------------------------------------------Phorum users all have their own profile. In this profile, data aboutthe user is stored. By default, Phorum stores for example theusername, email address and signature in the user profile. Alsouser settings like the privacy options are stored in there.You might want to add additional fields to the user profile. Exampleapplications for this are adding extra information that will bedisplayed in user profile screens or storing data and settings foryour mods (see also docs/creating_mods.txt, section 2.5).Phorum has an easy, built-in system to extend the profile fields,without requiring you to change the structure of the database. So there'sno need to actually add columns to the table in which Phorum users arestored in the database.This document will explain how to use the custom profile field system.2. Creating the custom field-------------------------------------------------------------------------------Go to the admin for your Phorum installation ({phorum url}/admin.php).There you go to "Custom Profiles" under "Users/Groups". In this screenyou can create, update and delete custom user profile fields.To add a field, you will have to enter the following data:* Field NameThis is the name that you are going to use for your custom field.It is not the display name for your field, but the internal name,which is used to reference the field from your code and HTML formelements. You are only allowed to use letters, numbers andunderscores (_) for this. So if you want to store the users's shoesize, you could for example use the field name "shoe_size".Remark:If you are creating a field for a mod, we recommend you to prefixthe field name with mod_<module name>, to prevent collisions withPhorum and other mods. So if you add the shoe_size for a modulenamed "foo", you would name the field "mod_foo_shoe_size".(see also creating_mods.txt, section 3.7.4).* Field LengthThis determines the length of the data that can be stored in thedatabase for the custom field. Data which is longer than thisvalue will be automatically truncated to the configured lengthbefore being stored in the database.* Disable HTMLIf this checkbox is enabled, all characters that have a specialmeaning in HTML will be automatically escaped when the field isretrieved from the database. This checkbox should always bechecked in case you are directly displaying the field data,without doing any data processing yourself. If you do not followthis rule, it might result in a XSS security problem (see alsocreating_mods.txt, section 3.6).If this checkbox is disabled, you will get the data exactlyas it is stored in the database. If you want to display thedata, you should take care of properly escaping HTML codeyourself.3. Using the custom field-------------------------------------------------------------------------------3.1 From the registration process---------------------------------If you want to let the user fill in the data for your customfield during registration, you will have to add an input field tothe registration template file, which can be found intemplates/default/register.tpl (or of course in your own templatedirectory if you are using a custom template).All you have to do is create a standard HTML input field and give itthe name of your custom field. Phorum will automatically take careof storing the field's data in the database.In the template you can make use of {REGISTER->fieldname} to getthe value of the field "fieldname". This can be used to let yourfield remember its value during requests.Example:To add the shoe_size field to the registration page, you couldadd the following code to the register.tpl at an appropriate place:<input type="text" name="shoe_size" value="{REGISTER->shoe_size}"/>3.2 From the user's control center----------------------------------If you want to give the user an option to change the value of yourcustom field from the control center, you will have to put an inputfield to the user settings template file, which can be found intemplates/default/cc_usersettings.tpl.3.3 From a module-----------------======================================================================Bits and pieces:You can use all HTML field types, but werecommend not to use checkboxes, because you will have to writespecial code to handle them. Instead you could use a <select>list with two options ("on" and "off").