Can I use visibility rules with user group?

  • 5uwebsite
  • Topic Author
  • Offline
  • Expert Boarder
  • Expert Boarder
  • Posts: 125
  • Thank you received: 2

5uwebsite replied the topic: Can I use visibility rules with user group?

Hi Mihaela,

I think I am missing the point 2.

2) Check whether you have an element in your form named "usergroupid" which will be filled with the group id.

So, I need to add an element in the form and named it as "usergroupid", but what do you mean will be filled with the group id?

Sorry, I am a bit confused about why and how to add this element.

Here is the screenshot's link: mrkr.io/s/5c38eccbc0a51e624331dd1c/0

Like what type of element should I choose? and what setting should I make for this element?

Please provide the instruction of how to add the "usergroupid" element.

Thank you a lot for your response and help.
#233256
  • Posts: 2735
  • Karma: 93
  • Thank you received: 369

mihaela replied the topic: Can I use visibility rules with user group?

Hello again,

I will explain a bit more.

Yes, you need to create a field in your form named "usergroupid". You need to have a field in your form filled with user group id so that you could write visibility rules and based on that group id ("usergroupid" filed) show or hide other fields in that form.

This code fills that field with the group id of logged in user.
$this->execPieceByName('ff_InitLib');

$user = JFactory::getUser(); 
$user_id ="$user->id"; 

if($user_id == '0' ) {
    $group_id = 0;
    }
else {
    $db = JFactory::getDBO();
    $db->setQuery("SELECT group_id FROM #__user_usergroup_map WHERE user_id =". $user_id);
    $group_id = $db->loadResult(); 
    }

ff_setValue('usergroupid', $group_id);

As for the "usergroupid" element type, it should be a "Hidden input" field because you don't want users to see this field when filing in the form.

Let me know whether now it is clearer how to set this to work.

Regards,

Mihaela
#233296
  • 5uwebsite
  • Topic Author
  • Offline
  • Expert Boarder
  • Expert Boarder
  • Posts: 125
  • Thank you received: 2

5uwebsite replied the topic: Can I use visibility rules with user group?

Hi Mihaela,

Thank you for explanation and help so far.

1. I checked two elements "Certicated_or_show", "Used_or_Leased" and the turn off fields have been checked.

2. I put the code that you gave at Form > Advanced > more options> Form Pieces > Before Form.

3. I created another element called "User Group ID", and do I need to fill php code in value field? cuz I found out that another "User ID" has php code in the value field.

Here is the screenshot's link of the User ID: mrkr.io/s/5c3d3557c26e6c2e55519633/0

Also, here is the screenshot's link of the user group id element I created:
mrkr.io/s/5c3d36674c4ef02365500cb7/0

If need to fill the php code in value field, can you provide the code for us?

Thanks a lot and appreciate for your patient.
#233322
  • Posts: 2735
  • Karma: 93
  • Thank you received: 369

mihaela replied the topic: Can I use visibility rules with user group?

Hello again,

From what you have explained it seems that you have set everything properly.

Regarding the 3. question, You don't need to fill php code in value field.

The code is there in "user ID" field to pull the id. Since the php code for getting user group id is bit more complex, it is placed in Before Form pieces as you placed it.

I'm not sure what might be the reason for this not to work. I've recreated the example base don the instructions I've given you and it is working fine at my site.

Only thing that crosses my mind is that you create "Textfield" named usergroupid instead of "Hidden input" just to see whether when you enter the form the group id is displayed in the usergroupid field.

Also, I have to note that you have to test this visibility rules in the frontend to see whether fields are showing/hiding properly and that the user from group with group id 10 or 11 has to be logged in.
It might be that you didn't preform the tests of this functionality properly.

Let me know whether the group number is displayed when you do as explaiend.

Best regards,

Mihaela
#233459
  • 5uwebsite
  • Topic Author
  • Offline
  • Expert Boarder
  • Expert Boarder
  • Posts: 125
  • Thank you received: 2

5uwebsite replied the topic: Can I use visibility rules with user group?

Hi Mihaela,

Thank you for your reply.

1. I checked the "Turn off" for those two elements (Used_or_Leased, Certificated_or_show).

2. Yes, I did create a hidden input named "usergroupid".
Here is the screenshot's link:
mrkr.io/s/5c463d7bcea7b1692ab7db78/0

Also, the visibility rule:
turn off element Used_or_Leased if usergroupid isnot 10
turn off element Certificated_or_show if usergroupid isnot 11
turn on element Used_or_Leased if usergroupid is 10
turn on element Certificated_or_show if usergroupid is 11

I put the code under Form pieces > Before Form:
mrkr.io/s/5c463ec151b09917dd6589d4/0

But still not working...

Those two fields still not display at the front-end.

Please help us take a look.

Thank you for your patient.
#233482
  • Posts: 2735
  • Karma: 93
  • Thank you received: 369

mihaela replied the topic: Can I use visibility rules with user group?

Hello again,

Ok, I see that you have done everything as needed.
But did you try to delete the hidden input named "usergroupid" and create a textfield named "usergroupid" and tested this in frontend to see whether the field is filled in with number 10 or 11 when you login as I've suggested in my previous post?

I think that the field is not filled in and that is the reason fields Used_or_Leased and Certificated_or_show are not showing. Id "usergroupid" is not filled in you can try to manually enter this numbers to see whether it is working.

Let me know the result.

Regards,

Mihaela
#233484
Moderators: ForumSupporttomeperica
Time to create page: 0.126 seconds

New Icon Packs Category!

Crosstec is now offering icon packs.

If you are a paying subscriber, icon packs are automatically added to your account.

Check out our icon packs page!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Summer Sale!

50% discount on all of our extension subscription plans, templates and icon packs!

Get Your Subscription Here

News and Updates

Get informed about new downloads, updates and more in our News and Updates newsletter.

All Extensions Subscription

Get 1 year access to all of our current and future products and 1 year of professional support -- 99 for just 49! (Summer Sale)

No support per domain or website installation limits! Includes all of our current and future Joomla!® extensions, Joomla!® templates for the duration of your membership. This means, by purchasing an All Extensions Subscription you'll have it all covered!

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Community Reward

Help us to create new extensions and plugins! With only $5 you help us a lot and get unlimited download access to all of our products, professional support and even more. Get your reward now!

Read More Here