Help php profile plugin

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
Tony85
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Thu Aug 04, 2016 8:25 am

Help php profile plugin

Post by Tony85 » Thu Aug 04, 2016 8:43 am

Hello Everybody,
I'm new to Joomla and php programming and I need some help to implement an idea :D !!
I'm developing a website with Joomla 3.6.1 and I need to customize registration form with some new fields.
So, what have I already done?
I copied the plugin "User - Profile" and I started modifying it.
So I modified profile.xml, profile.php accordingly to this guide, and everything works fine.
But, in this way, currently all new fields I added appear into the form without any condition.
Instead, I installed the "Usergroup Selector" plugin from Function 90 and what I want to reach is:
when I select Group1, only some fields must be displayed and when I select Group2 only other fields must be displayed, hiding fields related to Group1.
So I'm modifying my profileunical.php trying to add into "//Case registration" (row 174) a new condition to import usergroup selected from Usergroup Selector plugin and using this value into an IF statement to show some fields only when the condition is meet.

That's the piece of code I would like to improve (because actually do not works!):

Code: Select all

			// 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 == "Studente")
				{
					$form->setFieldAttribute($field, 'required', ($this->params->get('register-require_' . $field) == 2) ? 'required' : '', 'profileunical');
				}
				else
				{
					$form->removeField($field, 'profileunical');
				}
			}
I need to correctly import selected group and then use it into the subsequent IF statement to show or not a field.

Can someone help me ?

Thanks !!!

profileunical2.zip
You do not have the required permissions to view the files attached to this post.
Last edited by toivo on Thu Aug 04, 2016 9:21 am, edited 1 time in total.
Reason: mod note: moved to 3.x Coding

Tony85
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Thu Aug 04, 2016 8:25 am

Re: Help php profile plugin

Post by Tony85 » Fri Aug 05, 2016 9:04 am

I make a little adjustment to code:

Code: Select all

		//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 variable into registration from page (I can't see it).
If I could see what JRequest::getVar('usergroups'); get, I could understand where's the problem!
If I use $params->get('usergroups'); the code breaks!!
What's wrong :-[ :( :( !!


Locked

Return to “Joomla! 3.x Coding”