We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 46039
    • 76 Posts
    Hey, in the profile snippet from Login I'm trying to print extended fields in placeholders that are within parent containers.

    I'm not familiar enough with toplaceholder to see if the Login code is even allowing for this; or maybe this is an issue with how the JSON is converted into an array?

    The expected behaviour would be:

    [!Profile]
    [+email]
    [+user.id]

    Where [+user.id] is returning the field id within the user 'container'.
    It doesn't work.

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

      • 3749
      • 24,544 Posts
      Did you use this in the Profile tag?

      &useExtended=`1`


      This should give you the ID of the parent page:

      [[+parent]]


      This will give you the ID of the user who created the page:

      [[+createdby]]



      It's not clear to me what you want, but if you want extended fields for the user who created the parent page of the resource being processed, you'd have to use a custom snippet.
        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
        • 46039
        • 76 Posts
        Hey Bob, user and id are just arbitrary names I've given to extended user fields. User being the parent of id.

        Only id has a value, because user acts as a container for child values.
        • discuss.answer
          • 3749
          • 24,544 Posts
          First, I wouldn't use id and user for the names.

          If I'm understanding you, you want a field that's nested under the user field, which is an extended field for the current user.

          Profile doesn't handle nested arrays, so you'd have to do something like this:

          $profile = $modx->user->getOne('Profile');
          if ($profile) {
              $extended = $profile->get('extended');
              $modx->setPlaceholder('id_placeholder', $extended['user']['id']);
          } 


          If you will ever need to search and/or sort by these extended fields, you might want to look into ClassExtender. Searching or Sorting by extended fields is really slow and cumbersome.
            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
            • 46039
            • 76 Posts
            Cheers Bob.

            It's a bit annoying that it allows you to set nested values, but not get them without a custom snippet.

            The fields are only rarely used to link a users account to a third party UID, and to store additional contact info, nothing that needs sorting; but thanks for the advice.
              • 3749
              • 24,544 Posts
              The "it" that helps you create and store them is MODX, the "it" that lets you display their values is a third-party add-on component, so it's not fair to blame MODX for this.

              I'm not sure if anyone is currently maintaining the Login package, but it would make a good feature request (or contribution). A recursive function could set placeholders for the nested fields. I don't think many people use them, though. I find them really inconvenient to create, fill, edit, and retrieve.

              BTW, do you really need to nest them? Things would be a lot easier if it were a one-dimensional array.
                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
                • 46039
                • 76 Posts
                Very good point, sometimes the lines blur.

                I don't really need them, I just like the way the user manager interface displays the containers. It helps me visually separate the extra contact info from the third party UIDs.

                I'm not really at the level of confidence where contributing to an extra is a reasonable option. If I was at that stage I'd start fixing up SimpleSearch!
                  • 3749
                  • 24,544 Posts
                  BTW, if you want to make it really fast and easy, you can co-opt one or more unused fields in the User Profile (e.g., fax -- be careful of the types and sizes). You can change the Manager caption for the field (but not its actual field name) in Lexicon Management. [ed. note: BobRay last edited this post 8 years, 9 months ago.]
                    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
                    • 46039
                    • 76 Posts
                    Bob, I've reviewed everything and decided that your ClassExtender is probably the best option for future proofing all of this.

                    I've got a couple of issues though.

                    I cannot get the post hook snippet to fill out the fields via the registration form. Is there a certain way I should be formatting the ClassExtender fields?

                    Also, how do you handle boolean values in the registration form and the user profile editor? I have specified booleans in the extended fields XML and they show in the DB as tinyint, I just don't know how to handle changing them in MyExtraUserFields and the register form using checkboxes.

                    Any help would be much appreciated.
                      • 3749
                      • 24,544 Posts
                      Possible issues with the postHook snippet:

                      It needs to be above the register snippet on the page
                      It needs to be spelled correctly
                      It needs to be specified before any other postHooks
                      The Register form's submit button has to have name="loginRegisterBtn" and value="Register", unless you change the snippet code.

                      Checkboxes are always a pain and it always takes me several tries to get them right. As long as they name is the same as the extra user field and that name is a key in the $_POST, they should work. Adding this line to the top of the snippet might help you diagnose the problem:

                      echo '<p>' . print_r($_POST, true) . '</p>';


                      The post will be empty when the form first loads, but should be filled in when the form is submitted (assuming that you're not forwarding the user somewhere).

                      If it doesn't show up, use this instead and look in the error log:
                      $modx->log(modX::LOG_LEVEL_ERROR, print_r($_POST, true));


                      You can also uncomment lines 113 and 114 in the snippet to see if it's saving the user (look in the error log). You can put similar lines in other parts of the snippet (like at the top, to see if it's executing at all).
                        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