Add Custom User Profile Fields in Joomla – Step 3/3

Joomla 2.5 has reached its end of life as for 12/31/2014. Please be advised this may be a security risk to your website. You can view more information about the end of life here.

In our last few tutorials, we have been showing you the steps in how to add custom fields to the Joomla 2.5 user profile plugin. At this point we have copied the user profile plugin and updated the user facing form that asks them to enter in the new field. Our next step is to update the plugin’s parameters and allow the site Administrator to control whether the field is optional, required, or disabled.

Again, in this tutorial series we have been updating the Joomla 2.5 user profile plugin and adding a custom user profile field that allows the user to enter their favorite baseball team. We need to allow the site administrator to determine whether the user needs to add something for this field for not.

The first file we need to edit is:

plugins/user/profile10/profile10.php

We are making an update around line 171, and adding the following line (highlighted in red):

$fields = array(
        'address1',
        'address2',
        'city',
        'region',
        'country',
        'postal_code',
        'phone',
        'website',
        'baseballteam',
        'favoritebook',
        'aboutme',
        'tos',
        'dob',
);

The next file we will need to edit is:

plugins/user/profile10/profile10.xml

There are two entires we need to make:

  1. User profile fields for registration and administrator user forms

The first item controls the form users fill out when registering. We added the following at line 109:

<field name="register-require_baseballteam" type="list"

        description="During registration, if you have a favorite baseball team, enter it here."
        label="Favorite BaseBall Team"
>
        <option value="2">JOPTION_REQUIRED</option>
        <option value="1">JOPTION_OPTIONAL</option>
        <option value="0">JDISABLED</option>
</field>

The next item is added at line 248, and controls whether the user can edit the field’s value after they’ve initially registered and then try to edit their profile:

<field name="profile-require_baseballteam" type="list"

        description="If you have a favorite baseball team, enter it here."
        label="Favorite BaseBall Team"
>
        <option value="2">JOPTION_REQUIRED</option>
        <option value="1">JOPTION_OPTIONAL</option>
        <option value="0">JDISABLED</option>
</field>

The two options above can be seen when the Joomla 2.5 site administrator is editing the user profile plugin’s settings:
user-profile-plugin-manager

54 thoughts on “Add Custom User Profile Fields in Joomla – Step 3/3

  1. I found the problem with my optional fields showing up as mandatory when a person edits their profile. It was my mistake. There are 2 places that I had to set the fields as optional. I did that and it now works fine. The only issue outstanding is that I changed the ‘Region’ field to say ‘State’ instead of Region. It works fine on the initial registration page but still shows as Region on the Edit Your Profile. I changed the plugins\user\profile10\en-GB.plg_user_profile10.ini file to say

    PLG_USER_PROFILE_FIELD_REGION_DESC=”Choose an option for the field State.”
    PLG_USER_PROFILE_FIELD_REGION_LABEL=”State:”

    Do you know if I have to make a change to another file for it to show up on the Edit Your Profile.

    BTW: Your instructions are great. Your solution to my “Add New Fields To The Registration Form’ Is much better than anything else I have tried – and I tried something that cost $149 and your solution beats that one hands down. Thank You

  2. This is great information. Thank you. However, I do have a little problem.

    I have made the changes as instructed. In the admin screen I disabled the country field and made a couple of my new fields optional.Every thing works fine when a person registers. However, when they edit their profile the country field and all my optional fields are showing up as mandatory and I can save without entering data into these fields.  I am using Joomla 3.4.5. Could this be the problem?

    1. Hello Connie,

      These instructions are specific to version 2.5, so we cannot say how they work on another version. I would not believe following the instructions to cause the behavior you described, but without specifically being able to duplicate the issue, we are unable to say exactly what causes it.

      Kindest Regards,
      Scott M

  3. Can you help to tell me where to change it …. I can’t seem to take out the (optional) that shows next to my label “Address” (former address2)  https://www.sotube.us/basic  . I realy need it to show as required.

    I even put on plugins/user/profile/profiles/profile.xml to

    <field

    name=”address”

    type=”text”

    id=”address”

    description=”Addess that correspond to Account Type location”

    filter=”string”

    label=”Address:”

    size=”30″

     

    required=”true”

    —————————————————————–

    Regarding your sample above on both ends of the form I put

    <field name=”profile-require_address” type=”list”

     

    description=”PLG_USER_PROFILE_FIELD_ADDRESS_DESC”

    label=”PLG_USER_PROFILE_FIELD_ADDRESS_LABEL”

    >

    <option value=”2″>JOPTION_REQUIRED</option>

    <option value=”1″>JOPTION_REQUIRED</option>

    <option value=”0″>JDISABLED</option>

    </field>

    1. Hello Karin,

      Are you saying you are trying to remove the “Optional” option for the dropdown? Have you tried simply removing the OPtional tag, leaving the other two as they are?

      Kindest Regards,
      Scott M

  4. TJ

    Got it. Just edit the original profile and it works. Got another question. Is it possible to show fields only for the admin to edit and not for the user? I have got a memberid’s from an earlier system and I want to use those. So when the registered user want to change his profile he sees the memberid as text and not editable. Only the admin can change the memberid. Is it possible to make fields hidden too?

     

    Thnx Bert

    1. Hello Bert,

      Thank you for your question. I could not find a built-in way to accomplish this in Joomla, so you will most likely have to custom code/develop a solution.

      I did find a post online that may help, where they are discussing the creation of a field in a plugin that is only visible to admins.

      Thank you,
      John-Paul

  5. TJ

    It was not a complete blank install. But after your answer I disabled all plugins/components. Still the same issue!

     

    TJEdens says:

    Hello Bert, Have you tried this on a blank installation of Joomla or is this one you have been working on? Have you tried disabling some plugins/components to see if it alleviated the issue? Best Regards, TJ Edens

    Best Regards,
    InMotion Hosting Support Team

    1. Hello Bert,

      Have you tried this on a blank installation of Joomla or is this one you have been working on? Have you tried disabling some plugins/components to see if it alleviated the issue?

      Best Regards,
      TJ Edens

  6. Hi

    First thanks for this helpful post. One question regarding the profile fields, how to enable the custom fields only for the front end registeration. (i.e.,) I have to disable the custom field for the users added from the back end user manager by admin. Please do the needful. Thanks.

    1. Unfortunately, users are stored the same in Joomla regardless of how they are added. What you’re trying to do is technically possible, but would require custom code from your developer.

  7. Hi Arn, thank you for your quickly support.

    i’ve done every single step from your tutorial and i can see see fields.

    But when i change them to optional or required, it changes not at the frontend formular. The fields stay “optional”. i need them “required”.

    in your tutorial i can see, that the “baseballteam” field at the frontend either “optional” is.

    is there anything else to do, to set them required?

     

    Greetings

    Michael

     

    Arn says:

    Hello M. Grams, Thanks for the question. I just checked my install of Joomla 3.0 and when I follow the directions above, I was able to find the fields and the area where you can change them to say “required”. The tutorial above takes you through the steps to change it. Please follow those directions and you will be able to make the change. You will need to use the <a href=”https://www.inmotionhosting.com/support/edu/cpanel/cpanel-file-manager/using-file-manager-in-cpanel“>cPanel file manager</a> or your favorite FTP client to access the Joomla install files. Then you can make the edits as detailed above. If you have any further questions or comments, please let us know. Regards, Arnel C.

    Best Regards,
    InMotion Hosting Support Team

  8. My new Fields are allways “optional”. I want to set them “required”.

    I use Joomla 3.0

     

    Can anyone help

    1. Hello M. Grams,

      Thanks for the question. I just checked my install of Joomla 3.0 and when I follow the directions above, I was able to find the fields and the area where you can change them to say “required”. The tutorial above takes you through the steps to change it. Please follow those directions and you will be able to make the change. You will need to use the cPanel file manager or your favorite FTP client to access the Joomla install files. Then you can make the edits as detailed above.

      If you have any further questions or comments, please let us know.

      Regards,
      Arnel C.

  9. Hi all guys I want To add a new Field into The registration K2  form  And To See The new value into The K2 user table.  My version of Jolanda is 2.5. Thanks all.

    1. Hello Derrik,

      This particular series is for adding fields to the default User Profiles plugin for Joomla. We do not currently have a series for K2. Perhaps if you could give us all the details of what you are wanting to do and all the steps you have taken so far, we can assist you with your stickpoint.

      Be sure to give those details as a new question since it does not relate to this particular article.

      Kindest Regards,
      Scott M

  10. Thanks for the tutorial. Although i am very much late to view this, but i have a question. In admin panel, the field is displaying perfectly fine. But i am not able to see the input field on the front end form. Where i need to the change to make it viewable on front end.

     

    Thanks

Was this article helpful? Join the conversation!

Server Madness Sale
Score Big with Savings up to 99% Off

X