Home > joomla, web design > Adding Fields to Joomla 2.5 Registration Form

Adding Fields to Joomla 2.5 Registration Form

I am working on a project that requires a customized registration form for Joomla 2.5. On first glance it didn’t appear that Joomla 2.5 had much too offer. The closest thing I could find in the documentation was an article on how to create a profile plugin.

With additional research  I found information on a user profile plugin that has been around since Joomla 1.6. Unfortunately there was not too much information on how to modify from the Joomla Community. Luckily I ran across this article on stackoverflow. That told me what I needed to know. I did need to work out a few details on my own, though, and thought I would share the whole process in case it saves someone else some time.

The basic process is this:

  1. Activate the user profile plugin
  2. If you need to add a select box, add a table with the appropriate choices to your database.
  3. Edit the file plugins/user/profile/profile.xml – this will modify the plugin parameters on the backend, and on the profile edit page
  4. Edit the file plugins/user/profile/profiles/profile.xml – this will add the new field(s) to the registration form
  5. Add your new field parameters to the language file.

The user profile plugin comes with some useful fields and some not-so-useful fields. The person who decided that “Favorite Book” was a good default field definitely lives on a different planet than I do. But that’s OK.

If you only need to add text fields, your best bet is to just rename the default fields in the language file (location below). If you need a dropdown, select field though, you’ll need to do a little more.

Step One – Activate the user profile plugin. This should be self explanatory.

Step Two – Add the table with your dropdown choices to the database. If this isn’t self explanatory, then maybe you shouldn’t be trying this.

Step Three – Edit the following file:

plugins/user/profile/profile.xml

This will add your fields to the plugin administration and edit profile page. This is the basic format of the tag you’ll add, but you can copy, paste and modify any of the existing field tags in the file:

<field name=”role”

type=”list”
description=”PLG_USER_PROFILE_FIELD_ROLE_DESC”
label=”PLG_USER_PROFILE_FIELD_ROLE_LABEL”
>
<option value=”2″>JOPTION_REQUIRED</option>
<option value=”1″>JOPTION_OPTIONAL</option>
<option value=”0″>JDISABLED</option>
</field>

Step 4 – Edit the following file:

plugins/user/profile/profiles/profile.xml

This will add your field to the actual registration form. Since you’ve come this far I assume you’re adding a select field, and you’ll need to write the SQL to full that info from your new table.

Here’s my code:

<field
name=”role”
type=”sql”
id=”Role”
description=”PLG_USER_PROFILE_FIELD_ROLE_DESC”
filter=”string”
label=”PLG_USER_PROFILE_FIELD_ROLE_LABEL”
message=”PLG_USER_PROFILE_FIELD_ROLE_MESSAGE”
query=”SELECT role_id as value, role_name as role FROM #__myfield_role ORDER by role”
/>

Step 5 – Finally, name your parameters in the language file here:
administrator/language/en-GB/en-GB.plg_user_profile.ini

Hope that helps! Let me know if it works for you.

Similar Posts:

  1. No comments yet.
  1. No trackbacks yet.