We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28120
    • 380 Posts
    I need to add couple of extra fields to the User table, like "Company Name" and "Job Role"

    Aside from Extended Fields which seem a bit lightweight/bizarre is Extending modUser http://rtfm.modx.com/display/revolution20/Extending+modUser really the only way to go. This seems incredibly painful for something so simple.

    Also if I use Extended Fields, after looking around this forum, am I then going to suffer equal pain trying to modify


    Thanks
      • 22303 MODX Staff
      • 10,725 Posts
      Adding custom fields to the core MODX tables will break your upgrade path. We can not support direct customizations to our core data structures, and this is why the Extended profile fields are available for your use.

      If you need to search or sort by the custom data, I recommend extending modUser and/or adding a custom table related to modUser to store you data. It’s not that difficult and will be forward compatible because it isolates your customizations. You will have to provide another way of editing that custom data however. We’ll be doing some work to improve the flexibility of the core in the future so this can be integrated directly into the existing User Management UI.
        • 28120
        • 380 Posts
        Thanks

        If I’ve got to write some extra forms to maintain the extra data I’m sort of tempted to write the whole user management as an external for now and wait for your improvements to the core flexibility.

        I had a quick play with extended fields - is there a help doc on this? I couldn’t find it?

        From my quick test of extended fields it seems you have to redefine the name/value for each user record? Couldn’t see how to define the Name globally so it got prompted for all user records.
          • 28120
          • 380 Posts
          So my options are:


          • roll my own
          • use a standard field for another purpose

          Say I wanted to use the Fax field as Company Name. To make it easy for the enduser I thought it would be as easy as changing Fax to Company in Lexicon management, but I can’t find Fax? I tried editing $_lang[’user_fax’] = ’Company’; in user.inc but this doesn’t seem to have any effect.
            • 28120
            • 380 Posts
            ok, clearing the cache now shows ’Company’ instead of ’Fax’

            Is it bad for me to have edited user.inc.php - will this get over-written during an upgrade?

            I tried creating a Lexicon entry for user_fax but this doesn’t seem to be populating.

            All in all I’m really impressed with Modx Revolution and am totally committed to it; to the point where I have 2 sites live and 6 (yes 6) under development. However user profiles is the first hurdle that’s had me pulling my few remaining hairs out! My vote would be to give user profiles a template variables equivalent. In fact why not drop the template bit from template variables and just have variables, which could be attached to any object such resource, user, whatever?

              • 28120
              • 380 Posts
              One last desperate plea!

              Is there a more legitimate way to change the label ’Fax’ to ’Company’ other than editing user.inc.php?

              Thanks
                • 22303 MODX Staff
                • 10,725 Posts
                Overriding the lexicon in the database (via the UI) is the intended way of doing this. Does this not work for you?
                  • 34193
                  • 330 Posts
                  try

                  System->Lexicon Management

                  then change topic to user and carry out a search for Fax

                  Now double click on the value along side user_fax and change it to what ever you want

                  Now clear cache

                  And then look at the user profile.
                    • 3749
                    • 24,544 Posts
                    It sounds like you’ve already solved this, but you could also create extended fields for users to hold the extra information and use the UpdateProfile snippet in the Login package to edit them, or add them to the User Profile form with a plugin.

                    Repopurposing an existing user field will be give you faster performance and easier editing, however.
                      Did I help you? Buy me a beer
                      Get my Book: MODX:The Official Guide
                      MODX info for everyone: http://bobsguides.com/modx.html
                      My MODX Extras
                      Bob's Guides is now hosted at A2 MODX Hosting
                      • 28120
                      • 380 Posts
                      Oh joy - thanks Pete #8.

                      I hadn’t spotted there were 3 pages worth of stuff under the ’Topic’ dropdown! Thanks for sorting me out.

                      Re Bob’s point on extended fields; they’re sort of interesting but I’m not keen on using them because

                      a) you have to enter the name:value pairs. This is ok for me but when the client takes over they’d find it a lot easier if they could be prompted with the name and just enter the value

                      b) I like to know that if the client wants a report or export I’m capable of getting it direct from the database. I came up with this SQL to get the value from ONE extended field

                      SELECT LEFT(SUBSTRING(SUBSTRING_INDEX(SUBSTRING_INDEX(extended, ':', 3), ':', -1),2), CHAR_LENGTH(SUBSTRING(SUBSTRING_INDEX(SUBSTRING_INDEX(extended, ':', 3), ':', -1),2)) - 2) AS company
                      FROM modx_user_attributes


                      and that’s before any JOINS etc. so the following seems a lot less painfull

                      SELECT fax AS company FROM modx_user_attributes