First of all, thanks again Bob and Susan for your suggestions. I've been experimenting with some code (mostly other peoples) to try and display the extra fields in the New User Form with some limited success. To your earlier point Bob, about the difficulties of placing the fields where you want and formatting them - I see what you mean! But for now at least, I am just trying to return a list of coaches based on their membership of the Coaches User Group. I'm not getting very far. Here is my plugin code:
<?php
/**
* Add extra fields to New/ Modify User forms
*/
switch ($modx->event->name) {
case 'OnUserFormPrerender':
/* if you want to add custom scripts, css, etc, register them here */
break;
case 'OnUserFormRender':
$v = '';
if (isset($scriptProperties['resource'])) {
/* on the update screen, so set the value */
$v = $scriptProperties['resource']->get('longtitle');
} else {
/* on the create screen, so get all the coaches names */
$usergroup = 2; /* This is the Coach_ug */
$c = $modx->newQuery('modUser');
$c->innerJoin ('modUserProfile','Profile');
$c->innerJoin ('modUserGroupMember','UserGroupMembers');
$c->innerJoin ('modUserGroup','UserGroup','`UserGroupMembers`.`user_group` = `UserGroup`.`id`');
$c->leftJoin ('modUserGroupRole','UserGroupRole','`UserGroupMembers`.`role` = `UserGroupRole`.`id`');
$c->where(array(
'active' => true,
'UserGroupMembers.user_group' => $usergroup,
'UserGroupMembers.role' => '1',
));
$users = $modx->getCollection('modUser',$c);
foreach($users as $var => $value)
{
$profile = $modx->user->getOne('Profile');
$v = $profile->get('fullname');
}
}
/* now do the HTML */
$fields = '
<div class="x-form-item x-tab-item">
<p> '.$v.' </p>
</div>
';
$modx->event->output($fields);
break;
case 'OnUserFormSave':
/* do processing logic here. */
$resource =& $scriptProperties['resource'];
$resource->set('longtitle',$_POST['home']);
$resource->save();
break;
}
return;
At the moment I am only working with the code in the else statement of the OnUserFormRender case statement. My problem is that the only row I get returned from my query (well actually the query that I found here:
http://www.unchi.co.uk/2010/10/31/get-all-members-of-a-user-group-in-modx-revolution/ - with some minor modifications) is the Admin User who is NOT a member of the Coaches user group. I'm guessing the problem is in the foreach loop but my ignorance is stopping me from figuring out what. Any ideas?
[ed. note: gissirob last edited this post 10 years, 6 months ago.]