We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3109 ☆ A M B ☆
    • 894 Posts
    So I'm in the process of creating a user manager for a client of mine, I'm using the UpdateProfile snippet and the Peoples snippet, they both do exactly what I need them to do the problem is Update Profile can change the settings of the current logged in user I want to update a profile from one of the users listed on the Peoples list.

    I have 2 pages, a manage users page and a update user page. The manage users page contains the Peoples snippet call which lists all of my users and the update user page contains a UpdateProfile snippet call.

    So I created a tpl for my Peoples call this is what it looks like:

    <li class="[[+cls]]">[[+username]] - [[+id]] <a href="[[~23]]">Edit User</a></li>
    


    This lists all my users user name and ID and and it has a link to edit the user which links to the Update Profile page.

    I need to figure out how to pass the user ID from the Manage Users page to the Update User page so my client can update the selected users profile and save it on the front end.

    I find it odd that the Peoples extra does not do this by default but I will add this as a feature request, in the meantime I need to figure out how to accomplish this any help is appreciated.

    Thanks. [ed. note: benmarte last edited this post 14 years, 1 month ago.]
      Benjamin Marte
      Interactive Media Developer
      Follow Me on Twitter | Visit my site | Learn MODX
      • 3749
      • 24,544 Posts
      The easy way would be to append the ID to the URL for use with $_GET, though that would expose the user ID.

      I think it would be:

      <a href="[[~23? &userId=`[[+id]]`]]"


      How about putting a form in the Tpl chunk with no visible fields (and the user ID as a hidden field). It's submit button would be the only thing showing and the "action" would be the UpdateProfile page.

      I think you're going to have to modify the UpdateProfile snippet code no matter what, and it could read the $_POST array for the user's ID rather than using $modx->user. The user ID would still be visible in "View Source" but at least it wouldn't appear in the URL.

      If you really need to hide the user ID, I think you could use a snippet that set a $_SESSION variable. So, in the Tpl chunk, you'd have this somewhere outside what you have now:

      [[!SetUserId? &userId = `[[+id]]` ]]


      Then in the SetUserId snippet:

      <?php
      $_SESSION['userId'] = $scriptProperties['userId'];
      return '';
      


      The snippets should all execute before the page rendered.




      ------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using.
      MODX info for everyone: http://bobsguides.com/modx.html [ed. note: BobRay last edited this post 14 years, 1 month 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
        • 3109 ☆ A M B ☆
        • 894 Posts
        Bob after thinking about it last night I made the PeoplesTpl a select list and I am passing the user id as the value of each option using FormIt and Displaying it on the Update User page with FormItRetriever, the only thing left to do now is to get UpdateProfile to have an &id property to which I can pass the ID to.

        Is it too hard to edit the UpdateProfile snippet to do this?

        Thanks for your help.
          Benjamin Marte
          Interactive Media Developer
          Follow Me on Twitter | Visit my site | Learn MODX
          • 3109 ☆ A M B ☆
          • 894 Posts
          Making Progress I got the Update Profile page displaying all the selected users fields in the Update Profile form but when I make the changes and save it, it saves the changes in the current user not the selected user.

          So close, almost there.
            Benjamin Marte
            Interactive Media Developer
            Follow Me on Twitter | Visit my site | Learn MODX
            • 3749
            • 24,544 Posts
            Looking at the UpdateUser code, it appears that if the username or ID is set in $scriptProperties['user'] it will use that user for the whole process.

            Are you calling UpdateUser with a tag, or with $modx runSnippet()?

            In theory, one or the other of these should work:

            [[!UpdateProfile? &user=`[[+setUserId]]`

            $modx->runSnippet('UpdateProfile', array('user' => $userId));
            


            ------------------------------------------------------------------------------------------
            PLEASE, PLEASE specify the version of MODX you are using.
            MODX info for everyone: http://bobsguides.com/modx.html
              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
              • 3109 ☆ A M B ☆
              • 894 Posts
              Bob I'm going to post my code here so you can have a better idea of what Im doing.

              The way it works is on the Manage Users Page I have this code which lists all the users of a specific group, I'm using FormIt to pass the user to the Update User Profile page using FormItRetriever.

              Code for Manage Users Page:

              
              [[PeopleGroup? &usergroup=`Clients` &toPlaceholder=`users` &userTpl=`AloUserTpl`]]
               
              [[!FormIt?
                 &submitVar=`edit`
                 &hooks=`redirect`
                 &store=`1`
                 &redirectTo=`23`
              ]] 
               
              <h2>[[+peoplegroups.name]] ([[+peoplegroups.userCount]] Users)</h2>
                                        
              <form action="[[~[[*id]]]]" method="post">                       
              <label class="label">Select User To Edit</label>
              <select name="user-id">
              [[+users]]
              </select>
              <input type="submit" class="submit" name="edit" value="Edit User" />
              </form>  
              
              


              Code for Update user Profile page:

              
              [[!FormItRetriever? &eraseOnLoad=`1`]]
              
              [[!UpdateProfile? &user=`[[!+fi.user-id]]`]]
              
              <h2>User Name is: [[!+fi.user-id]]</h2>
              
              [[$AloUpdateProfile]]
              
              


              The AloUpdateProfile chunk has the Update Profile Form which can be seen here

              The issue is when saving the update profile it is updating the current user that's logged in not the selected user.

              I tried using:

              [[!UpdateProfile? &user=`[[!+fi.user-id]]`]]
              


              But I don't see that as a parameter for the UpdateProfile I also tried using

              
              [[!UpdateProfile? &syncUsername=`[[!+fi.user-id]]`]]
              
              


              But that also did not achieve the results I wanted, thanks for your help.
                Benjamin Marte
                Interactive Media Developer
                Follow Me on Twitter | Visit my site | Learn MODX
                • 3749
                • 24,544 Posts
                I was going by this code in the UpdateProfile snippet:

                 public function getUser() {
                        $user = $this->getProperty('user',false);
                        if (!empty($user)) {
                            $c = intval($user) == 0 ? array('username' => $user) : intval($user);
                            $this->user = $this->modx->getObject('modUser',$c);
                        } else {
                            $this->user =& $this->modx->user;
                        }
                        if (empty($this->user)) {
                            $this->modx->log(modX::LOG_LEVEL_ERROR,'Could not find user: '.$user);
                        }
                        return $this->user;
                    }


                I can't see why this didn't work:

                [[!UpdateProfile? &user=`[[!+fi.user-id]]`]]



                Can you tell if the fi.user-id placeholder is being set?


                ------------------------------------------------------------------------------------------
                PLEASE, PLEASE specify the version of MODX you are using.
                MODX info for everyone: http://bobsguides.com/modx.html
                  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
                  • 3109 ☆ A M B ☆
                  • 894 Posts
                  Bob the placeholder is being passed I know this because it's populating the UpdateProfile Form with the correct user data and the page has an H2 tag with the which displays the selected user name.

                  Update Profile doesn't have user as a parameter the closest thing is syncUser and that didn't achieve anything to my knowledge.

                  Ok I just checked my error log and it's giving me this:

                  (ERROR @ /index.php) Could not find user: [[!+fi.user-id]]
                  


                  This is my AloUserTpl:

                  <option value="[[+username]]" [[!+fi.user-id:FormItIsSelected=`[[+username]]`]] >[[+username]]</option>
                  


                  Thanks for checking. [ed. note: benmarte last edited this post 14 years, 1 month ago.]
                    Benjamin Marte
                    Interactive Media Developer
                    Follow Me on Twitter | Visit my site | Learn MODX
                    • 3109 ☆ A M B ☆
                    • 894 Posts
                    Bob, thanks for all your help and guidance I finally managed to get it working. I made a lot of changes but I think it was due to my own stupidity.

                    This does indeed work:

                    [[!UpdateProfile? &user=`[[!+fi.user-id]]`]]
                    


                    Anyways this will be a great tutorial that I'm sure a lot of users will find useful.

                    Thanks again. [ed. note: benmarte last edited this post 14 years, 1 month ago.]
                      Benjamin Marte
                      Interactive Media Developer
                      Follow Me on Twitter | Visit my site | Learn MODX
                      • 3749
                      • 24,544 Posts
                      Ben, I'm glad you got it working.

                      You probably know this, but snippets can have properties that are not listed on the properties tab and sometimes they're not listed in the docs either.

                      The UpdateProfile snippet code is definitely checking for the &user property, so if it were added via the snippet tag, the default properties, or a property set, it should work like any of the listed properties.


                      ------------------------------------------------------------------------------------------
                      PLEASE, PLEASE specify the version of MODX you are using.
                      MODX info for everyone: http://bobsguides.com/modx.html
                        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