We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36624
    • 535 Posts
    Hello,

    i need to know the date a user created his profile (they create their account on front-end).

    But i didn't see any useful existing date in the modUser object (http://www.shawnwilkerson.com/modx/2012/03/10/programmatically-working-with-the-moduser-object/).

    Anyone know if this date exist and hide somewhere else ? or should i use an extended field and save the date at registration ?

    Thanx for your hints.

    This question has been answered by nuan88. See the first response.

      CTRL+SHIFT+U - Clear Cache
      CTRL+SHIFT+H - Hiding Heft Panel
      CTRL+SHIFT+N - Fast Create Resource
      CTRL+ALT+P - Preview Recource (in edit resorce window)
      CTRL+ALT+S - Save
      • 3749
      • 24,544 Posts
      This is the full list of the modUser object fields: http://bobsguides.com/modx-object-quick-reference.html#modUser. No date fields at all, I'm afraid.

      The modUserProfile object has the 'extended' field, but it's a pain to work with since it holds a JSON string that's converted to an array when you retrieve it. In order to interact with it in the Manager, you have to 'create' the field for each user and you can't easily access it directly with a placeholder as you can with the other fields.

      There are a number of other User Profile fields you could Co-opt if you're not using them (e.g., phone, mobilephone, country, fax, photo, comment, etc.) You can see the length of each of them here (in the [fieldMeta] section). It's easy to change the captions for them in Lexicon Management so you can identify the one you want when you edit a user.

      You'll need a plugin to save them during registration, as you suggest. The big decision is whether to save them as human-readable dates or Unix timestamps. It's easy enough to convert from one to the other (and there are MODX output modifiers for it). The timestamp option is usually better, since you can do easy date comparisons and searches, and you can change the displayed format of them without messing with your code.

      A whole other approach would be to add a new field with ClassExtender, but if you can use one of the existing fields, it will be faster and easier. If you go this route, don't use 'createdon' as the field name as it will conflict with that resource field.

        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
      • Actually the userinfo output modifier does handle extended fields, although (at least as far as I can tell) not nested extended fields.
        [[!+modx.user.id:userinfo=`extended.fieldname`]]
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
        • discuss.answer
          • 46886
          • 1,154 Posts
          As far as I have been able to determine the system does not log this value.

          One user whitebyte kindly provided a custom snippet to put in your registration form which will fix this data, here:

          http://forums.modx.com/thread/95745/how-to-add-registration-date

          I have implemented it and it works fine. However I have not yet figured out how to display this info, but that's not too tough.
          • That snippet uses the Extended field. Depending on how you want to use the data, there are several ways to get at the extended fields.
            [[!<user-id>:userinfo=`extended.registerdate`]]
            will do it in an output modifier. If you've stored it as a timestamp, you'll need to add one of the date/time modifiers:
            [[!<user-id>:userinfo=`extended.registerdate`:date=`%Y`]]

            http://bobsguides.com/blog.html/2013/11/03/understanding-modx-extended-fields-and-json/
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 46886
              • 1,154 Posts
              Ah thank you Susan. I made two fields, one a timestamp which would need the date modifier, the other a value which would just output. I will play with this and see how it works.
                • 40088
                • 708 Posts
                I'm using the snippet that @whitebyte provided (with Login/Register) but am having trouble displaying the result using Susan's example above.

                Not sure what to do with this !<user-id>. Could someone provide an explicit example? [ed. note: todd.b last edited this post 6 years ago.]
                  Todd
                  • 3749
                  • 24,544 Posts
                  I don't know that snippet, so I'm guessing here, but this might work:

                  [[![[+modx.user.id]]:userinfo=`extended.registerdate`:date=`%Y`]]


                    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
                    • 46886
                    • 1,154 Posts
                    Did this work out? I thought i would have a solution, but I don't unfortunately.

                    This seems to work for username and ID

                    [[!+modx.user.username]]


                    but not for anything else, even values in the main profile like email and fullname

                    Maybe dob can work but..that's weird.

                    You may be left needing a snippet to output some of this data, but i am not sure. Anyway I found this thread in which there are several solutions

                    https://forums.modx.com/thread/95538/help-with-displaying-extended-user-fields
                      • 46886
                      • 1,154 Posts
                      Hey also this works

                      [[+modx.user.id:userinfo=`createdon`]]


                      If your createdon fields (again in the basic profile) are populated, I guess that's automatic for register snippet, as I didn't find that field in my code.

                      So that means you can get a date out there directly from the simple profile. You would have dob (date of birth) as a time field as well which you could repurpose if you wanted, birthday for example.

                      The key issue would be not going into extended fields for key info, which can slow things down a lot if you need to check those values a lot.