We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • Thanks Bruno - I'll give it a test and get back to you.
      Helen Warner
      Number one pixel!
      Proud to be linked with MODX at Crimson Pixel
    • All ways a new learning curve!!

      Ok I've tried to get this to work but to no avail.

      My call to populate a form ready for updating is:

      [[!Profile? &user=`11` &prefix=`Profile_`]]

      My form is as follows:
      [[!FormIt?
      &submitvar=`submit` 
         &hooks=`updateHook`
         &validate=`fullname:required,
          email:email:required`
      ]]
      
      <h1>Update Profile</h1>
      <div class="update-profile">
          <div class="updprof-error">[[+error.message]]</div>
          [[+login.update_success:is=`1`:then=`[[%login.profile_updated? &namespace=`login` &topic=`updateprofile`]]`]]
       
          <form class="form" action="[[~[[*id]]]]" method="post">
              <input type="hidden" name="nospam" value="" />
       
              <label for="fullname">[[!%login.fullname? &namespace=`login` &topic=`updateprofile`]]
                  <span class="error">[[+error.fullname]]</span>
              </label>
              <input type="text" name="fullname" id="fullname" value="[[+Profile_fullname]]" />
       
              <label for="email">[[!%login.email]]
                  <span class="error">[[+error.email]]</span>
              </label>
              <input type="text" name="email" id="email" value="[[+Profile_email]]" />
       
              <label for="phone">[[!%login.phone]]
                  <span class="error">[[+error.phone]]</span>
              </label>
              <input type="text" name="phone" id="phone" value="[[+Profile_phone]]" />
       
              <label for="mobilephone">[[!%login.mobilephone]]
                  <span class="error">[[+error.mobilephone]]</span>
              </label>
              <input type="text" name="mobilephone" id="mobilephone" value="[[+Profile_mobilephone]]" />
       
              <label for="fax">[[!%login.fax]]
                  <span class="error">[[+error.fax]]</span>
              </label>
              <input type="text" name="fax" id="fax" value="[[+fax]]" />
       
              <label for="address">[[!%login.address]]
                  <span class="error">[[+error.address]]</span>
              </label>
              <input type="text" name="address" id="address" value="[[+Profile_address]]" />
       
              <label for="country">[[!%login.country]]
                  <span class="error">[[+error.country]]</span>
              </label>
              <input type="text" name="country" id="country" value="[[+Profile_country]]" />
       
              <label for="city">[[!%login.city]]
                  <span class="error">[[+error.city]]</span>
              </label>
              <input type="text" name="city" id="city" value="[[+Profile_city]]" />
       
              <label for="state">[[!%login.state]]
                  <span class="error">[[+error.state]]</span>
              </label>
              <input type="text" name="state" id="state" value="[[+Profile_state]]" />
       
              <label for="zip">[[!%login.zip]]
                  <span class="error">[[+error.zip]]</span>
              </label>
              <input type="text" name="zip" id="zip" value="[[+Profile_zip]]" />
       
              <label for="website">[[!%login.website]]
                  <span class="error">[[+error.website]]</span>
              </label>
              <input type="text" name="website" id="website" value="[[+Profile_website]]" />
       
              <br class="clear" />
       
              <div class="form-buttons">
                  <input type="submit" name="login-updprof-btn" value="[[!%login.update_profile]]" />
              </div>
          </form>
      </div>


      And my snippet which I've called "updateHook" as per the information provided is:

      $success = true;
      $data = $hook->getValues();
      $extended = array();
       
      foreach ($data as $key => $value) {
          $field = explode('.', $key);
       
          if (count($field) > 1) {
              //extended field (json-array)
              if ($field[0] == 'Profile_extended') {
                  $extended[$field[1]] = $value;
                  unset($data[$key]);
              }
          } elseif (substr($key, 0, 8) == 'Profile_') {
              $data[substr($key, 8)] = $value;
              unset($data[$key]);
          }
       
      }
      $data['extended'] = $extended;
      
      $data['fullname'] = $data['Profile_fullname'];
      $data['email'] = $data['Profile_email'];
      $data['phone'] = $data['Profile_phone'];
       
      $response = $modx->runProcessor('security/user/update', $data);
       
      if ($response->isError()) {
          $success = false;
          $errormsg = $response->getMessage();
      }
       
      return $success;


      And nothing in the error log....

      Have I done it incorrectly?
        Helen Warner
        Number one pixel!
        Proud to be linked with MODX at Crimson Pixel
      • The UpdateProfile snippet accepts the User ID from the $scriptProperties array and should load that user, allowing you to edit it. SO you can make a (heavily protected) form that the site manager could login to, and they can specify the user ID to edit. IF I'm reading this right: https://github.com/modxcms/Login/blob/develop/core/components/login/controllers/web/UpdateProfile.php#L120

        you should also be able to pass in a username, and getObject will query that against the user table.
          [sepiariver.com] (https://sepiariver.com/)
        • THIS ONE ANSWERS MY QUESTION! wink

          Quote from: sepiariver at Dec 02, 2014, 08:10 PM
          The UpdateProfile snippet accepts the User ID from the $scriptProperties array and should load that user, allowing you to edit it. SO you can make a (heavily protected) form that the site manager could login to, and they can specify the user ID to edit. IF I'm reading this right: https://github.com/modxcms/Login/blob/develop/core/components/login/controllers/web/UpdateProfile.php#L120

          you should also be able to pass in a username, and getObject will query that against the user table.

          Hey - great to get more input.

          So I've tried calling:

          [[!UpdateProfile? &user=`11`]]

          And whilst this does actually load the form there are no details. (Note: I have disabled redirect to unauthorise page which means it would load!! If unauthorise page is active it doesn't actually load)!

          If you preceed this with:

          [[!Profile? &user=`11`]]

          Then the user details load but I don't seem to be able to update them!

          PS - And totally agree this needs careful use of permissions as to who can actually access / manage this information!

          UPDATE - If I log in to the front end as manager and then visit the Update Profile page with the &user=`11` this does produce the users information but I still can't seem to update it.

          UPDATE - Obviously not seeing the blinking obvious! Have two pages which I'm testing and was on the wrong flipping page. This does work. By making use of &user with UpdateProfile snippet it would seem this is now quite doable!

          Thank you everyone for your input as always. [ed. note: boomerang last edited this post 9 years, 6 months ago.]
            Helen Warner
            Number one pixel!
            Proud to be linked with MODX at Crimson Pixel
          • This is my setup, I have 2 pages the first page the administrator selects which user they want to modify and then once they make the selection it sends them to another page which loads the update profile page with the user they selected. I'm sure this could be done a better way but I just needed to do something quick and have it work.

            Anyways this is my select user page markup:

            [[!PeopleGroup? &usergroup=`Clients` &getProfile=`1` &toPlaceholder=`users` &userTpl=`AloUserTpl2` &limit=`0`]]
             
            [[!FormIt?
               &submitVar=`edit`
               &hooks=`redirect`
               &store=`1`
               &redirectTo=`79`
            ]] 
             
             
             
            
            <div class="postbox">
            
                <div class="postboxmain">   
            
            <h2>Select User To Edit</h2>                       
            
            <form id="target" action="[[~[[*id]]]]" method="post">                       
            
            <input type="hidden" value="[[!+fi.user-id]]" name="user-id" id="user-id"/>
            
            <ul id="edit-user-selected">
                [[+users]]
            </ul>
            
            <input type="submit" class="submit" name="edit" value="Edit User" />
            
            </form>
            
            </div>
            
                <div class="postboxfooter"></div>
            					
            </div>
            


            This is the code for the Update Profile page:

            [[!FormItRetriever]]
            
            [[!UpdateProfile? &user=`[[!+fi.user-id]]`]]
            
            
            <div class="update-profile">
            
                <div class="updprof-error">[[+error.message]]</div>
               
                [[+login.update_success:if=`[[+login.update_success]]`:is=`1`:then=`[[%login.profile_updated? &namespace=`login` &topic=`updateprofile`]]`]]
            
                <form class="form" action="[[~[[*id]]]]" method="post">
                    <input type="hidden" name="nospam:blank" value="" />
             
                    <label for="fullname">[[!%login.fullname? &namespace=`login` &topic=`updateprofile`]]
                        <span class="error">[[+error.fullname]]</span>
                    </label>
                    <input type="text" name="fullname" id="fullname" value="[[!+fullname]]" />
                    
                    <label for="blocked">Block User
                        <span class="error">[[+error.blocked]]</span>
                    </label>
                    <input type="hidden" name="blocked" id="blocked" value="[[!+blocked]]" />
                    <select id="blocked-select" name="blocked-select">
                        <option value="0">No</option>
                        <option value="1">Yes</option>
                    </select>
                    
                   <label for="blockedafter">Block User After
                        <span class="error">[[+error.blockedafter]]</span>
                    </label>
                    <input type="hidden" name="blockedafter" value="[[!+blockedafter]]"/>
                    <input type="text" name="blockedafter" id="blockedafter" value="[[dateconverter? &date=`[[!+blockedafter]]`]]" />
                    
                    <label>Last Login</label>
                    <p>[[!+lastlogin]]</p>
            
                    <label for="email">[[!%login.email]]
                        <span class="error">[[+error.email]]</span>
                    </label>
                    <input type="text" name="email:required:email" id="email" value="[[!+email]]" />
             
                    <label for="phone">[[!%login.phone]]
                        <span class="error">[[+error.phone]]</span>
                    </label>
                    <input type="text" name="phone" id="phone" value="[[!+phone]]" />
             
                    <label for="mobilephone">[[!%login.mobilephone]]
                        <span class="error">[[+error.mobilephone]]</span>
                    </label>
                    <input type="text" name="mobilephone" id="mobilephone" value="[[!+mobilephone]]" />
             
                    <label for="fax">[[!%login.fax]]
                        <span class="error">[[+error.fax]]</span>
                    </label>
                    <input type="text" name="fax" id="fax" value="[[+fax]]" />
             
                    <label for="address">[[!%login.address]]
                        <span class="error">[[+error.address]]</span>
                    </label>
                    <input type="text" name="address" id="address" value="[[!+address]]" />
             
                    <label for="country">[[!%login.country]]
                        <span class="error">[[+error.country]]</span>
                    </label>
                    <input type="text" name="country" id="country" value="[[!+country]]" />
             
                    <label for="city">[[!%login.city]]
                        <span class="error">[[+error.city]]</span>
                    </label>
                    <input type="text" name="city" id="city" value="[[!+city]]" />
             
                    <label for="state">[[!%login.state]]
                        <span class="error">[[+error.state]]</span>
                    </label>
                    <input type="text" name="state" id="state" value="[[!+state]]" />
             
                    <label for="zip">[[!%login.zip]]
                        <span class="error">[[+error.zip]]</span>
                    </label>
                    <input type="text" name="zip" id="zip" value="[[+!zip]]" />
             
                    [[!checkUser:eq=`1`:then=`<label for="website">File Share URL</label>
                        <span class="error">[[+error.website]]</span>
                    
                    <input type="text" name="website" id="website" value="[[!+website]]" />`]]
             
                    <br class="clear" />
             
                    <div class="form-buttons">
                        <input type="submit" class="submit" name="login-updprof-btn" value="[[!%login.update_profile]]" />
                    </div>
                </form>
            </div>
            
            


            I don't use MODX that much anymore so hopefully this helps you get to where you need to get.

            Good luck.
              Benjamin Marte
              Interactive Media Developer
              Follow Me on Twitter | Visit my site | Learn MODX
            • That's great benmarte was intending to use FormitRetreiver &store so good to see that was how you've done it. Thanks for sharing the info.

              Perfect for anyone else who might be looking to achieve the same thing.

              :)
                Helen Warner
                Number one pixel!
                Proud to be linked with MODX at Crimson Pixel