Get selected group to use in another plugin

2 years 11 months ago #1 by Antonello Mancuso
Hello friends,
I installed on my website "Usergroup selector plugin" to allow new registratnt to select their group directly from front end registration form.
Now I'm developing a custom plugin to customize the registration form (it's a custom user profile plugin that adds some new field into Joomla profile).
I would like that, when user select its group into registration form (using userselector), fields of my custom plugin appear or disappear, based on which group is selected.
So I'm implementing into my "profileunical.php" file something like this:
// Case registration
elseif ($name == 'com_users.registration')
{
$plugin = &JPluginHelper::getPlugin('user', 'usergroupselector');
$pluginParams = new JRegistry($plugin->params);
$params->get('usergroups','default_value');
$cgroup = $params;
// Toggle whether the field is required.
if ($this->params->get('register-require_' . $field, 1) > 0 && cgroup == "Istituto")
{
$form->setFieldAttribute($field, 'required', ($this->params->get('register-require_' . $field) == 2) ? 'required' : '', 'profileunical');
}
else
{
$form->removeField($field, 'profileunical');
}
}
But there's an error because I cannot get the selected group and plugin doesn't work (blank page!). Could you help me?
Thanks!

File Attachment:

File Name: profileunical2.zip
File Size:7 KB
Attachments:
2 years 11 months ago #2 by Function90
Hello Antonello,

Thanks for contacting us.
We have developed such extension already. www.function90.com/products/joom-profile.html
You can look into demo at demo.function90.com/joom-profile/register.html

Thank you
Team Function90
You can share your views regarding our extension at JED ( extensions.joomla.org/profile/profile/details/225115#extensions )

Hire Professional Joomla Developers. ( www.function90.com/contact-us.html )
2 years 11 months ago #3 by Antonello Mancuso
I don't think is the same.
I tried the demo. Despite of the usergroup selected (Group1 or Group2) the subsequent informations (fields) required into the form are the same!
Instead, I would like that if I select Group1, only some fields appears and when I select Group2 other fields appear (hiding that related to Group1).
However... the price is quite high for me, so I'll appreciate if you can tell me simply if sintax of this part of the code is correct:
$plugin = &JPluginHelper::getPlugin('user', 'usergroupselector');
$pluginParams = new JRegistry($plugin->params);
$params->get('usergroups','default_value');
$cgroup = $params;
Thanks!
2 years 11 months ago #4 by Function90
Hello ,

Regarding JoomProfile, Group1 and Group2 are joomla usergroups. And you have seen the fields on second step after filling the first, there will be different set of fields. On our demo fields are same on first screen, so it is not showing the difference,

and the code you wrote seems okay. Let me know if it doesn't work.

Thank you
Team Function90
You can share your views regarding our extension at JED ( extensions.joomla.org/profile/profile/details/225115#extensions )

Hire Professional Joomla Developers. ( www.function90.com/contact-us.html )
2 years 11 months ago - 2 years 11 months ago #5 by Antonello Mancuso
First, thanks for your answer.
However, I opened two times link of demo in two different tabs of my browser and I filled the form choosing in one tab Group1 and in 2th tab Group2, but I seen the same fields in all pages. But, if you tell me that it's possibile to differentiate fields, I believe you.

Regarding the code, I'm looking at usergroupselector.php because I would like to understand, when the user choose a group from Front End, in which variable is saved the result. So that I can call/import the value of that variable in my code and proceed.
I wrote this:
//Load usergroupselector plugin
$plugin = &JPluginHelper::getPlugin('user', 'usergroupselector');		//load your plugin
$pluginParams = new JRegistry($plugin->params);   //get parameters
$params->get('usergroups','default_value');    //get choosen group ?? It's usergroups the variable that contains the group choosed by user into Front End?
$cgroup = $params;     //save result in my internal variable to use next into the code
echo $cgroup;    //I add this for now as check (I would like to check if the correct value is selected)

However, when I load the registration page (with my plugin installed, obviously) it crashes (I see only a white page... internal error 500: server can't handle the request).

I know you're not held to answer, but I'll appreciate if you can tell me how to select the right variable.
Thanks!
2 years 11 months ago #6 by Antonello Mancuso
I make a little adjustment:
		//Load usergroupselector plugin
		$plugin = &JPluginHelper::getPlugin('user', 'usergroupselector');		
		$pluginParams = new JRegistry($plugin->params);
		$params = JRequest::getVar('usergroups');
		$cgroup = $params;
		echo ("Selected group: " .$_POST['cgroup']."<br />\n");

Now it doesn't break the page. However, I cannot print $cgroup into registration form page (I can't see it).
What is wrong ?? :oops: :(
2 years 11 months ago #7 by Function90
You want to get post value from registration or usergroups from plugin params?

Thank you
Team Function90
You can share your views regarding our extension at JED ( extensions.joomla.org/profile/profile/details/225115#extensions )

Hire Professional Joomla Developers. ( www.function90.com/contact-us.html )
2 years 11 months ago #8 by Antonello Mancuso
When a new User is filling the registration form, he will choose a group from selector, right?
I want THAT group!
Surely, you save that value into a variable because, at the end of the process, you assign the new User at the group he has chosen.
So, I think I don't need the parameters but the VALUE after (POST) user selected it.
I hope now my request is clear.
Thanks :)
2 years 11 months ago #9 by Function90
use like
$input = JFactory::getApplication()->input;
$requestData  = $input->post->get('jform', array(), 'array');
var_dump($requestData['usergroupselector']);

Thank you
Team Function90
You can share your views regarding our extension at JED ( extensions.joomla.org/profile/profile/details/225115#extensions )

Hire Professional Joomla Developers. ( www.function90.com/contact-us.html )
2 years 5 months ago #10 by Alexandra Gallio
Hello, I am trying to do something similar and i didn't have success with the vardump method but i can retrieve and use the parameters like this :
//Load usergroupselector plugin
$plugin = &JPluginHelper::getPlugin('user', 'usergroupselector'); //load your plugin
$ParamsUGS = new JRegistry($plugin->params);   //create new object and get parameters
echo ("<br />ParamsUGS: <span style='color:green;'>" . $ParamsUGS . "</span> >> Name of variable: <span style='color:red;'>\$ParamsUGS</span>" );	 //show parameters

$allowed_groups = $ParamsUGS->get('allowed_groups'); //get allowed_groups from parameters
echo ("<br />Allowed group: >");
	 		foreach($allowed_groups as $groupid){
	 				echo ("<span style='color:green;'>" . $groupid . "</span>");	
					echo"-";
	 		}
echo " >> Name of variable: <span style='color:red;'>\$allowed_groups</span>";
$first_value_group = reset($allowed_groups);  //get first allowed groupid value from parameters
echo ("<br />First value of allowed groups: <span style='color:green;'>" . $first_value_group . "</span> >> Name of variable: <span style='color:red;'>\$first_value_group</span>" );	
$first_key_group = key($allowed_groups); //get first allowed groupid key from parameters
echo ("<br />First key of allowed groups: <span style='color:green;'>" . $first_key_group . "</span> >> Name of variable: <span style='color:red;'>\$first_key_group</span>" );				
$first_groupid = array_values($allowed_groups)[0]; //get first allowed groupid from parameters
echo ("<br />First groupid: <span style='color:green;'>" . $first_groupid . "</span> >> Name of variable: <span style='color:red;'>\$first_groupid</span>" );	
$second_groupid = array_values($allowed_groups)[1]; //get second allowed groupid from parameters	
echo ("<br />Second groupid: <span style='color:green;'>" . $second_groupid . "</span> >> Name of variable: <span style='color:red;'>\$second_groupid</span>" );		
$label = $ParamsUGS->get('label'); //get label from parameters
echo ("<br />Label: <span style='color:green;'>" . $label . "</span> >> Name of variable: <span style='color:red;'>\$label</span>" );	
$desc = $ParamsUGS->get('desc'); //get desc from parameters
echo ("<br />Description: <span style='color:green;'>" . $desc . "</span> >> Name of variable: <span style='color:red;'>\$desc</span>" );	
$required = $ParamsUGS->get('required'); //get required from parameters
echo ("<br />Required: <span style='color:green;'>" . $required . "</span> >> Name of variable: <span style='color:red;'>\$required</span>" );	
$allowMultiple = $ParamsUGS->get('allowMultiple'); //get allowMultiple from parameters
echo ("<br />Allow multiple: <span style='color:green;'>" . $allowMultiple . "</span> >> Name of variable: <span style='color:red;'>\$allowMultiple</span>" );	
$default_group = $ParamsUGS->get('default_group'); //get default_group from parameters
echo ("<br />Default group: <span style='color:green;'>" . $default_group . "</span> >> Name of variable: <span style='color:red;'>\$default_group</span>" );
2 years 5 months ago #11 by Function90
Hello Alexandra,

Please let me know what you want to do, by using above code? It will be better for me to explain you in right direction.

Thank you
Team Function90
You can share your views regarding our extension at JED ( extensions.joomla.org/profile/profile/details/225115#extensions )

Hire Professional Joomla Developers. ( www.function90.com/contact-us.html )
2 years 5 months ago #12 by Alexandra Gallio
Hello,

I am trying to add users to groups in the custom registration plugin of my ads component but it has worked.
Maybe because the code you wrote were already written in the usergroupselector plugin.
It has worked after i added the values of the select options and without other things to add.
<select class="required" name="jform[usergroupselector]" id="jform_usergroupselector" value=""  >
<option value="<?php echo $first_groupid ?>">account 1</option>
<option value="<?php echo $second_groupid ?>">account 2</option>
</select>

Thanks a lot for you great plugin, now visitors can choose between two sort of accounts.
Best regards
2 years 5 months ago #13 by Function90
Hello Alexandra,

Glad to know that it is working for you.
It will be great if you can share your views on JED
extensions.joomla.org/extensions/extensi.../usergroup-selector/

Thank you
Team Function90
You can share your views regarding our extension at JED ( extensions.joomla.org/profile/profile/details/225115#extensions )

Hire Professional Joomla Developers. ( www.function90.com/contact-us.html )
2 years 5 months ago #14 by Alexandra Gallio
Hello,

I posted my review on JED !

Thanks again, it works fine :P

Best regards
Powered by Kunena Forum
Cron Job Starts