We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 436 ☆ A M B ☆
    • 265 Posts
    Has anyone seen a snippet or script which could get a list of users, functioning like getResources? I've been looking around but I've not been able to find a solution yet.

    Specifically, I need to implement quick front-end search (like AJAX search) for a user via their profile phone number, anyone got any tips how they'd do that?
      MODX Ambassador for Thailand. Managing Director at Monogon, a web design and development studio based in Bangkok, Thailand. - Follow me on Twitter.
      • 22427
      • 793 Posts
      Perhaps the Addon Peoples could be helpful (but I don't have own experience with it).
        • 3749
        • 24,544 Posts
        You could possibly do it with Peoples, but a custom snippet would be a lot more efficient.

        Something like this (assumes that you don't need the username):


        $profile = $modx->getObject('modUserProfile', array('phone' => $phone));
        
        if ($profile) {
           $placeholders = $profile->toArray();
           $modx->setPlaceholders($placeholders);
        } else {
            return "User Not Found";
        }
        


        You'd have to make a form and have the snippet get the phone number when it's submitted. The problem is that the phone number would have to be formatted exactly as it is in the database, and that may vary from user to user unless you format it when you first save the user.

        You could solve that by creating a drop-down list of phone numbers to select from, but your users probably wouldn't approve of having their phone numbers available to bots.
          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