Hello,
Following the tutorial at: http://www.chronoengine.com/faqs/61-cfv4/cfv4-tutorials/4618-how-can-i-add-a-user-to-a-user-group.html, I have been unable to add my users to custom usergroups.
The code I used is:
The structure of Events and Actions is such that upon "Joomla! Registration" (Which I do on clicking a "Submit" button), there are further events: "On success" and "On failure". The above code is run "On success" and is a "Custom Code".
In "Joomla! Registration", I have set User Groups to 10. And that is what is being assigned in the database.
Any help would be greatly appreciated!
Following the tutorial at: http://www.chronoengine.com/faqs/61-cfv4/cfv4-tutorials/4618-how-can-i-add-a-user-to-a-user-group.html, I have been unable to add my users to custom usergroups.
The code I used is:
<?php
if ( !isset($form->data['membership_type']) ||
!$form->data['membership_type'] ) {
// there is no membership_type selected
return false;
}
$group_array = array (
'0' => '11', //Corporate
'1' => '12', //Individual
'2' => '13', //Student
);
$group_id = $group_array[$form->data['membership_type']];
$user_id = $form->data['_PLUGINS_']['joomla_registration']['id'];
jimport( 'joomla.user.helper' );
JUserHelper::addUserToGroup($user_id, $group_id);
?>
The structure of Events and Actions is such that upon "Joomla! Registration" (Which I do on clicking a "Submit" button), there are further events: "On success" and "On failure". The above code is run "On success" and is a "Custom Code".
In "Joomla! Registration", I have set User Groups to 10. And that is what is being assigned in the database.
Any help would be greatly appreciated!
Hello saketjain,
I'm not a Chrono professional, but after checking your new post, I think that the following links may help:
How can I add a User to a User Group?
How can I ask new users for information and not ask logged in users?
P.S: I'm just an automated service😉
I'm not a Chrono professional, but after checking your new post, I think that the following links may help:
How can I add a User to a User Group?
How can I ask new users for information and not ask logged in users?
P.S: I'm just an automated service😉
Hi saketjain,
The code looks OK to me. I suggest that you add a Debugger action to see exactly what values are being set and used in the function. It may be that CFv5 no longer adds the new User ID to the same parameter as CFv4 :-(
Bob
The code looks OK to me. I suggest that you add a Debugger action to see exactly what values are being set and used in the function. It may be that CFv5 no longer adds the new User ID to the same parameter as CFv4 :-(
Bob
Thank you! I'll try doing that and see what's the output.
I do have one clarification that I needed to make. While the group_id is being set as 10(the value set in the joomla! registration), it is also being set as 12 (the correct value).
Now 10 is also a parent of 12.
My question is, is this normal behavior?
I do have one clarification that I needed to make. While the group_id is being set as 10(the value set in the joomla! registration), it is also being set as 12 (the correct value).
Now 10 is also a parent of 12.
My question is, is this normal behavior?
Hi saketjain,
Sorry. I have no idea. I looked at the code and ChronoForms isn't adding any extra groups but it is possible that the Joomla! Registration process adds a parent group as well.
Bob
Sorry. I have no idea. I looked at the code and ChronoForms isn't adding any extra groups but it is possible that the Joomla! Registration process adds a parent group as well.
Bob
The Joomla registration action should add the user to the configured groups only, I have some code which will add the user to extra groups, this is for v5 only:
The code above adds the logged in user to the group with id = 10
Regards,
Max
<?php
$user = \GCore\Libs\Base::getUser();
$user_id = $user["id"];
if(!\GCore\Admin\Models\GroupUser::getInstance()->field('user_id', array('user_id' => $user_id, 'group_id' => 10))){
\GCore\Admin\Models\GroupUser::getInstance()->save(array('user_id' => $user_id, 'group_id' => 10), array('new' => true));
}
The code above adds the logged in user to the group with id = 10
Regards,
Max
This topic is locked and no more replies can be posted.