<![CDATA[ How to add User Group to Form Customization Profile through API? - My Forums]]> https://forums.modx.com/thread/?thread=80312 <![CDATA[How to add User Group to Form Customization Profile through API?]]> https://forums.modx.com/thread/80312/how-to-add-user-group-to-form-customization-profile-through-api#dis-post-442523 I am thankfull in advance for any help.
I am using MODX Revolution 2.2.4-pl (advanced).
I am trying to create member pages. This issue has been raised many times and several users have suggested working solutions (like Bob Ray's tree_root_id solution and the ACL-based resource and user control).
I have posted my own, ACL-based solution on gist - "own" is actually a gross exaggeration - it is copied-pasted and adapted from several solutions offered by the community (credited in the gist). Be aware though: errors are entirely mine, and I am a non-coder.
The plugin is fairly simple: on UserFormSave, it creates a corresponding resource, resource group, user group, the necessary access controls and group memberships, and a file directory.

But how do I assign the created User Group to an existing Form Customization Profile?

I have tried

$fields = array( 'usergroup' => 25, 'profile' => 2);
$FCPUG = $modx->newObject('modFormCustomizationProfileUserGroup', $fields);
if($FCPUG->save()) {echo 'Success!';}

It does not work. Is it because I can't modify a relationship table?

Then I tried, without success either:
$FCPUGs = $modx->getCollection('modFormCustomizationProfileUserGroup');
$FCprofile = $modx->getObject('modFormCustomizationProfile', 2);
$FCprofile->addMany($FCPUGs);
if($FCprofile->save()) {echo 'Success!';}

In the http://bobsguides.com/modx-object-full-reference.html#modFormCustomizationProfile"" target="_blank" rel="nofollow">object reference (thanks to Bob Ray for it) modFormCustomizationProfile objects have a related object UserGroups (from modFormCustomizationProfileUserGroup).
How do I add one or several User Group to this related object?
Thank you in advance for your help!

Update: I see that lukemcd posted the same question on the forum 4 months ago. But he received no answer and posted no solution.]]>
marcelliru Nov 07, 2012, 08:51 AM https://forums.modx.com/thread/80312/how-to-add-user-group-to-form-customization-profile-through-api#dis-post-442523
<![CDATA[Re: How to add User Group to Form Customization Profile through API?]]> https://forums.modx.com/thread/80312/how-to-add-user-group-to-form-customization-profile-through-api#dis-post-553333
// $fields = array( 'usergroup' => 25, 'profile' => 2);
$FCPUG = $modx->newObject('modFormCustomizationProfileUserGroup');
$FCPUG->set('usergroup', 23);
$FCPUG->set('profile', 2);
if($FCPUG->save()) {echo 'Success!';}



Some MODX objects won't allow setting fields in the newObject() call.]]>
BobRay Aug 24, 2017, 08:33 PM https://forums.modx.com/thread/80312/how-to-add-user-group-to-form-customization-profile-through-api#dis-post-553333
<![CDATA[Re: How to add User Group to Form Customization Profile through API?]]> https://forums.modx.com/thread/80312/how-to-add-user-group-to-form-customization-profile-through-api#dis-post-553307
I am working on something that requires the exact same thing.

Cheers]]>
pranawebdesign Aug 23, 2017, 10:04 AM https://forums.modx.com/thread/80312/how-to-add-user-group-to-form-customization-profile-through-api#dis-post-553307