Want users 2 join ACL group through front end profile plugin
Posted: Fri Mar 16, 2012 4:35 pm
I have created a group called "subscriber" and I want the users to be able to choose to join this group simply by clicking a radio button when registering or changing their profile options. Then I will send an email to all users in this group concerning updates and etc. from the company. I would prefer not to have to manually add them all to this group based on requests in email or what have you. I really want this to be automatic.
Since the User Manager in 2.5 has the option to do a Mass Mail simply by selecting which groups to send to, I think this is a logical solution, if only I can figure out how to assign this group through some sort of php script directly associated with the profile plugin. Any ideas, of course, are totally welcome.
Thanks to using code from this: http://docs.joomla.org/Creating_a_profile_plugin I've got the radio buttons made, now I just need to make them do something!
Any ideas peoples!?
=======
UPDATE
=======
Ok, this is going to be embarrassing, but seeing as I don't know PHP, I think I've gotten pretty close to cobbling together some code for this, but it still doesn't work. I'm probably making some terrible simple syntax error and just don't know it. Anyway, I have come up with this code to add to the profile.php file that "comes with" Joomla.
Here's what I did.
I added these imports to the top of profile.php
And then inside of the onUserAfterSave function I added... (my addition is after the comments)
--------------------------------
If I un-comment the line:
then when I use the front end register form to create a new user they are automatically added to the "subscriber" group (and the registered group) every time, which I can see in the back end, by going to the user manager.
So my problem appears to be in retrieving the value from the radio button.
The line above:
Isn't getting it done.
Hopefully this is a simple PHP fundamental thing that I will figure out soon...
Thanks in advance
Cheers!
ultramanjones
Since the User Manager in 2.5 has the option to do a Mass Mail simply by selecting which groups to send to, I think this is a logical solution, if only I can figure out how to assign this group through some sort of php script directly associated with the profile plugin. Any ideas, of course, are totally welcome.
Thanks to using code from this: http://docs.joomla.org/Creating_a_profile_plugin I've got the radio buttons made, now I just need to make them do something!
Any ideas peoples!?
=======
UPDATE
=======
Ok, this is going to be embarrassing, but seeing as I don't know PHP, I think I've gotten pretty close to cobbling together some code for this, but it still doesn't work. I'm probably making some terrible simple syntax error and just don't know it. Anyway, I have come up with this code to add to the profile.php file that "comes with" Joomla.
Here's what I did.
I added these imports to the top of profile.php
Code: Select all
jimport( 'joomla.user.helper' );
jimport( 'joomla.user.user');
jimport( 'joomla.utilities.arrayhelper' );
Code: Select all
function onUserAfterSave($data, $isNew, $result, $error)
{
$userId = JArrayHelper::getValue($data, 'id', 0, 'int');
//
//BEGIN CUSTOM CODE
//
//put this inside the onUserAfterSave function in profile.php
// This code will check if the user clicked the radio button for email
// updates by checking the 'subscribe' boolean in the data
// then assign the user to that group (group 9) if true
$groupID = 9; //9 is the value for the subscriber group in the ACL
$subscribeFlag = JArrayHelper::getValue($data, 'subscribe', 0, 'boolean');
//DEBUG code that forces if statement to come up true
//$subscribeFlag = 1;
echo $subscribeFlag;
if (!($subscribeFlag == 0))
{
try
{
JUserHelper::addUserToGroup($userId, $groupID);
}
catch (JException $e)
{
$this->_subject->setError($e->getMessage());
return false;
}
}
//END CUSTOM CODE
//
If I un-comment the line:
Code: Select all
//$subscribeFlag = 1;
So my problem appears to be in retrieving the value from the radio button.
The line above:
Code: Select all
$subscribeFlag = JArrayHelper::getValue($data, 'subscribe', 0, 'boolean');
Hopefully this is a simple PHP fundamental thing that I will figure out soon...
Thanks in advance
Cheers!
ultramanjones