Access Usergroup Invalid - Joomla!

@cheesegrits / @mediaateam
I tried to use this code onAfterProcess in juser plugin. I am not sure that is correct. The main goal is that add user to the group which he create while registration. It is my N-afford to get answer on this question even on professional forum. I am became disappointed.


PHP:
$userid = $formModel->getElementData('user_registration_form___username', true);
$gid = $formModel->getElementData('user_registration_form___companyid', true);
if (!empty($userid) && !empty($gid)) {
JUserHelper::addUserToGroup($userid, $gid);
}
But I am getting error
Access Usergroup Invalid - Joomla!

How I can fix this problem?
 
I tried to use this code onAfterProcess in juser plugin. I am not sure that is correct. The main goal is that add user to the group which he create while registration

Where are you creating that group? And how are you creating it?

You seem to be trying to use a 'companyid', but unless that's a join to the J! group table, that won't work.

-- hugh
 
I still don't understand what you are trying to do. You never answer my questions.

You said:

The main goal is that add user to the group which he create while registration

I asked:

Where are you creating that group? And how are you creating it?

The code you have just adds a user to an existing group. So are you creating that group elsewhere? In your other thread on this, I seem to recall you referenced a thread from earlier this year where I gave someone else the code they need to create a new usergroup. Are you running that code somewhere?

-- hugh
 
I have answered on your question. Where I am trying to do it. I have form on my site. The id of this form is 19.

I have wrote it in the previous message. I added php plugin on this form and input the mentioned code.
PHP:
$userid = $formModel->getElementData('user_registration_form___username', true);
$gid = $formModel->getElementData('user_registration_form___companyid', true);
if (!empty($userid) && !empty($gid)) {
JUserHelper::addUserToGroup($userid, $gid);
}


If you go on my site you will see it.

I am not running code which you mentioned earlier this year. I tried but had the same issue.
 
I am continue struggling with my issue.
For adding user to the group I am using next code(different variant are commented). Errors are concerning with uncommented:

PHP:
//$userid = $formModel->getElementData('user_registration_form___username', true);
//$gid = $formModel->getElementData('user_registration_form___companyid', true);
//if (!empty($userid) && !empty($gid)) {
  // JUserHelper::addUserToGroup($userid, $gid);
//}
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('MAX('.$db->quoteName('id').')');
$query->from($db->quoteName('#__usergroups'));
$db->setQuery($query);
$result = $db->loadResult();
// // Display results in a message
JFactory::getApplication()->enqueueMessage($result, 'type');

echo $result;
exit;

// Get the connected user
$user = JFactory::getUser();

echo $user;exit;

// Add the user in the group ID = x
JUserHelper::addUserToGroup($user->get('id'), $result );
// reload the user object so the user is connected with its new access rights
$session = JFactory::getSession();
$session->set('user', new JUser($user->get('id')));
Case 1 : with Email
If I am using email in juser. While executing of this code I have message that my email already exists. then
case1.png
If am clicking on the submit one more time I getting message that my usergroup already exists. What is obviously for me.


Case 2: without email
juser_case2.png
I am getting

Some parts of your form have not been correctly filled in

Mentioned code is on the plugin in the form id 19.

How can I fix it?
 
We are in need of some funding.
More details.

Thank you.

Staff online

Members online

Back
Top