Working on a recent project for a client, it became clear to that we needed to hack the standard JomSocial registration process to capture extra user information during the registration process. Crucially - this data needed to be stored in Joomla's jos_user table, and not JomSocial's own external tables.
We couldn't find any step-by-step guides on the internet, so we've shared our findings with you here:
The project features a subscription-based registration, plus a social networking integration. We used AEC for the actual subscriptions (and handling the payments) and Azrul's JomSocial for social networking to create an extensive paid member-only network.
Collecting Extra Data
Jomsocial does in fact allow you to capture extra user registration information on sign up - so called "Custom Profiles".
There's a handy back-end utility for this but it posed a couple of problems for us:
- The data was stored in the database in a highly normalised way, with each "Custom Profile Field" being stored across a row and a lookup table for the fields attributes. This is to be expected with this kind of extensible application but provided issues for our client retrieving the data from the database and manipulating it themselves.
- It became far too complicated to hide JomSocial fields from other users, and it was simply impossible to have admin-only fields (such as internal reference numbers for processing applications and so forth).
- If for some reason in the future we moved away from JomSocial, we wanted to ensure that the data was stored in Joomla's standard jos_user table and there was no danger of this data being lost. It was simply too crucial to our client to risk this.
- We needed to manipulate the extended profile data using com_user in the Joomla admin user manager, which we have also modified.
The Solution
A basic breakdown of the process:
- Create a new table column for each of the data items you require in each of the tables for JomSocial and Joomla in the database (jos_users & jos_community_register). Keep a note of the exact column names you use as they'll be needed later.
- Edit the file libraries/joomla/database/table/user.php. The code we're looking for is around line 118 (search for var $params = null;). You'll notice each variable (e.g. var $params) is named the same as the
database columns in jos_users. Create a new line of code for each of your new database columns - the easiest way to do this is to copy and paste the block of code for each variable, modifying the variable name for each of your required new database columns.
Example - (assuming you new database columns are "foo" and "bar") the code needs to be:
var $foo = null;
var $bar = null; - The next step will depend on the template you've used. Navigate to /components/com_community/templates/[template name] and look for the file register.index.php. If it doesn't exist, you'll find it in /components/com_community/templates/default.
This is the registration form where you need to add the new form elements that relate to your new database columns. For simplicity we suggest you set the name and id of the form elements to be exactly the same as the name of the database columns to which they relate.
You may also make use of JomSocial's built in form validation at this point. The standard form uses a number of different validation options that you can copy and use on your own elements. Sadly JomSocial have not documented the validation options at present so you'll have experiment until you get it right. - As with step 3, look for the file profile.edit.details.php in your [template name] folder, and if you can't find it there then look in the /default folder. You need to copy and paste the form elements that you added in step 3 to this form. Because you've added the columns into Joomla's user data layer (as completed in step 2), you can now easily access the data in the tables by setting the value attribute for the form element to be "echo $user->get(foo);" where foo is column name. Simple!
- Edit the file com_community/models/register.php at approximately line 46. You need to copy the syntax from above and add a line for each database column and its form element name:
Example:
$obj->foo = $data['foo'];
$obj->bar = $data['bar'];
Your new form elements will now appear on the registration form and also the edit details tab of JomSocial's edit profile page. A quick test registration should also show that each form element writes to the appropriate database column.
It's as simple as that! Good luck and feel free to comment if you have any questions.












