We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 44922
    • 131 Posts
    I'm trying to take a user's extended field, which actually contains an array, turn it into a string, then pass to a placeholder. The snippet is part of a posthook on the UpdateProfile extra.

    Even through I have something similar working elsewhere, I can't get this to work. My placeholder only displays the last value (in this case "UK"). Grateful for any help.

    An example of the extended field from the modx_user_attributes database: "Location":["Spain","Switzerland","UK"],

    The snippet code I'm using:
    // get user profile
    
    $profile = $modx->user->getOne('Profile');
    	
    // get user extended field values
    
    $extended = $profile->get('extended');
    
    // turn the array into a string
    
    $userlocation = $extended['Location'];
    
    $userlocations = implode(",", $userlocation);
    
    // set placeholder
    $modx->setPlaceholder('Location2','$userlocations');
    
    return true;


    to output to placeholder [[+Location2]]
      • 44922
      • 131 Posts
      Got this to work, not as a posthook but as a separate snippet. I call this snippet on the users' profile / dashboard page along with [[!Profile]] snippet.

      The [[!Profile]] snippet doesn't like arrays in the user's extended fields and just returns empty placeholders on the users profile dashboard.

      So this way, using <input type="checkbox" name="Location[]" > on the update profile page, the [] after the "name" extends the extended field to take multi select - an array of values - when the updateProfile snippet is called. You could do the same with <select name="Location[]">.

      Using the above snippet from the previous post with (or without) [[!Profile]] means I can use the placeholder in the above snippet if the extended field is an array. It will then display all the values. For single values, (username etc) the profile extended placeholders handle that just fine.
        • 3749
        • 24,544 Posts
        Good tip, thanks for reporting that.

        BTW, you might be interested in this: http://bobsguides.com/blog.html/2014/05/27/why-extend-moduser/
          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
          • 44922
          • 131 Posts
          Thank Bob. I was aware from Bruno that there were better ways - it's just this project is already way down the line and we're in a client post-launch-extended-functionality situation. Certainly will check this out in future.