We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 45766
    • 78 Posts
    Hi,

    is it possible to edit the group of an user with the UpdateProfil Snippet?

    I would like to have that people can set a checkbox for Groups they would like to be a member of.

      • 5430
      • 247 Posts
      Don't believe so, that snippet is purely for altering user profile data, which does not include user permission settings. Pretty sure you'd have to use a custom hook to incorporate this functionality.
      https://docs.modx.com/extras/revo/login/login.tutorials/login.using-pre-and-post-hooks
        • 3749
        • 24,544 Posts
        You might look at the Subscribe extra. It provides the option for users to update their group memberships as well as their interests/tags.

        Subscribe is meant to work with the Notify extra to send the users emails containing a link to the page that lets them change their preferences, but I think you can present the "Manage Preferences" form on its own without installing Notify.
          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
          • 45766
          • 78 Posts
          Hi claytonk:
          Thanks for the info i thought so too but was not sure.

          Hi bob:
          Thanks for the Tipp! If I saw right the login extra has the functionality to choose groups too. But as your extra it is also just for new users if they fill in the register form. If they want to change it it's not possible. Right?
          For me the groups are important because I would like to use the people extra and it just works with groups not with extended fields.
          I also found your snippet which allows to list all users which have an extended field or an special value in it. Would be perfect, but I need to sort the result an Filter for more than one field.
          Maybe I try to enhance it on my own - even though I am just a designer wink
            • 45766
            • 78 Posts
            YEAH! I made my own Solution smiley

            I wrote a postHook that looks at to form fields. Depending what they contain the user will be added or removed from a group.

            Here is how i did it

            Call at the Template
            [[!UpdateProfile? &postHooks=`userToGroup`]]
            <div class="formGroup width-100">
            		  		<label for="showMemberregister">Label</label>
            		  		<select name="showMemberregister">
            		  			<option value="hide" [[!+showMemberregister:is=`hide`:then=`selected`]]>Hode</option>
            		  			<option value="show" [[!+showMemberregister:is=`show`:then=`selected`]]>Show</option>
            		  		</select>
            		  	</div>
            



            Snippet: userToGroup
            <?php
            	// A reference to the modUser object
            	$user = $hook->getValue('updateprofile.user');
            	
            	// A reference to the modUser object
            	$formFields = $hook->getValues();
            	$memberregister = $formFields['showMemberregister'];
            	$expertregisterregister = $formFields['showExpertregister'];
            	
            	if ($memberregister == 'show') {
            	    $user->joinGroup('Expertregister','Member');
            	}
            	
            	if ($expertregister == 'show') {
            	    $user->joinGroup('Memberregister','Member');
            	}
            	
            	if ($memberregister == 'hide') {
            	    $user->leaveGroup('Expertregister','Member');
            	}
            	
            	if ($expertregister == 'hide') {
            	    $user->leaveGroup('Memberregister','Member');
            	}
            	
            	return true;
            
              • 3749
              • 24,544 Posts
              Hi bob:
              Thanks for the Tip! If I saw right the login extra has the functionality to choose groups too. But as your extra it is also just for new users if they fill in the register form. If they want to change it it's not possible. Right?

              No, the users can use the same form to change their group membership at any time, but since you've found a solution, Subscribe may be overkill for your use case, though it's really handy for registering new users, and I think it's more secure than the Register package by itself.

                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
                • 45766
                • 78 Posts
                thanks. i will have a look at it!