On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • Hi guys - I can access information about the user using filters (in Revo) such as [[++userId:userinfo=`email`]] -- how would I access information entered as ’extended fields’ on a user?

    For example, I created an extended field called ’test’ with some value - it is included in the database under the ’extended’ field as {"test":"If this shows, win!"}

    And I guess, as an extended question, how is the best way to approach creating a set of extended fields that apply to a particular group of users? So, I create a new user in the manager, select a user group, and am presented with extra fields to complete (or some other way that achieves the same thing)

    Thanks! smiley
      --
      cal wilson
      oksushi.com
    • One way for now would be to simply set those as placeholders in a Snippet, e.g.
      <?php
      $modx->toPlaceholders($modx->user->Profile->get('extended'), 'userext');
      ?>

      Then you can reference it as:
      [[+userext.test]]

      ...in your content.
      • Thanks for the reply Jason!

        Apologies in advance for what is probably a newbie mistake, but putting that snippet on the page (I called it GetExtendedFields) gives me the following error when I view the resource:

        Fatal error: Call to a member function get() on a non-object in /path/to/revo/core/cache/elements/modsnippet/21.include.cache.php on line 7

        I tried calling it cached and uncached.

        What have I missed?
          --
          cal wilson
          oksushi.com
        • Try this:
          $profile = $modx->user->getOne('Profile');
          $modx->toPlaceholders($profile->get('extended'), 'userext');
          
            shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
          • My code was assuming you had already loaded the Profile; sorry for the confusion.
            • Thanks to you both, it works a treat!
                --
                cal wilson
                oksushi.com
              • Everything you’ve said makes sense, but I am not sure why I am not getting anything thing returned when I do this:

                $profile = $user->getOne('Profile');
                $profile->get('phone'); // WORKS
                $profile->get('Company') // Doesn't work although I do have an extended field saved as 'Company'


                Data stored as:

                {"Region":"Asia Pacific","Company":"My Company"}
                • Quote from: keiron77 at Oct 25, 2010, 08:48 AM

                  $profile = $user->getOne('Profile');
                  $profile->get('phone'); // WORKS
                  $profile->get('Company') // Doesn't work although I do have an extended field saved as 'Company'


                  Data stored as:

                  {"Region":"Asia Pacific","Company":"My Company"}

                  That’s not how it works. You need to get() the extended field and then get the attributes from it, e.g.
                  <?php
                  $extended = $profile->get('extended');
                  echo $extended['Company'];
                  echo $extended['Region']; 
                  

                  The "extended" field is stored in the database as JSON and returned by the get() function as a PHP array.
                  • I thought there was a step I was missing out.

                    Saying "The ’extended’ field is stored in the database as JSON and returned by the get() function as a PHP array.", actually makes it really obvious now.

                    Cheers
                    • I am trying to manually create user extended fields under the dozen users I have.

                      I click on add attribute and fill out the form and then hit save, but nothing saves the form remains. Is there something I need to turn on?