TOPIC:

Can I use visibility rules with user group? 1 year 7 months ago #233018

  • Topic Author
  • 5uwebsite
  • Offline
  • Senior Breezer
  • Senior Breezer
  • Posts: 126
  • Thanks: 2
Hi there,

Visibility rule is great! It can be used to deal with many different situations. May I ask whether I can use the current user's user group as a condition? For example, the user of the "Public" group can see an element, while the user of the "Registered" group will see another element. Is that possible?

Thanks,

Please Log in or Create an account to join the conversation.

Can I use visibility rules with user group? 1 year 7 months ago #233097

  • mihaela
  • Offline
  • Developer
  • Developer
  • Posts: 3128
  • Karma: 105
  • Thanks: 414
Hello,

Yes, it is possible to achieve what you want.

Here is how you can achieve what you want.
If user is logged in (registered), he will have a user ID assigned. On the other hand if the user is not logged in when filling in the form he won't have assigned user ID.

Therefore, you can make this work in a way that you fill a hidden form field with user's ID and then show/hide fields depending on the value of that field.

So, to achieve what you want, follow this steps:

1) Create a Hidden input field in your form named "userid". In the Value field in that element's properties put the following code:
<?php $user = JFactory::getUser(); return "$user->id"; ?>

2) Let's assume that you have fields "field1" and "field2" and that you want to display field1 for public and field2 for logged in users.
Then you would write this visibility rules:
turn off element field1 if userid isnot 0
turn off element field2 if userid is 0

turn on element field1 if userid is 0
turn on element field2 if userid isnot 0

This is an example. You can write as many visibility rules as you want.

The important part is that public will have user ID "0", and logged in users (registered) won't.

Let me know whether this helped and whether you've managed to set this for your form.

Regards,

Mihaela

Please Log in or Create an account to join the conversation.

Can I use visibility rules with user group? 1 year 7 months ago #233108

  • Topic Author
  • 5uwebsite
  • Offline
  • Senior Breezer
  • Senior Breezer
  • Posts: 126
  • Thanks: 2
Hi Mihaela,

Now we have another question about turn on and off conditional set up.

There are two fields that only can display one each at the time in the form for different user group (both of the user groups are registered groups).

Please check this screenshot's link: mrkr.io/s/5c339dc03262a8237cbc02be/0

There are two user groups with id from Joomla backend:

Non-verified member (ID: 10) and Verified member (ID: 11)

The question is how to write the turn on/off, when I want"Used_or_Leased" radio button field display in the form when a user logged in as a "Non-verified member".

On the other hand, I want a login user who is in verified user group to see "Certificated_or_show" field only.

Here is the formula I write but it does not work:
turn off element Used_or_Leased if userid isnot 10
turn off element Certificated_or_show if userid is 10
turn on element Used_or_Leased if userid is 10
turn on element Certificated_or_show if userid isnot 10


Please help us take a look, and provide the solution.

Thank you for your patient.

Please Log in or Create an account to join the conversation.

Can I use visibility rules with user group? 1 year 7 months ago #233174

  • mihaela
  • Offline
  • Developer
  • Developer
  • Posts: 3128
  • Karma: 105
  • Thanks: 414
Hello again,

In that case you need to write an SQL query to get the id of the usergroup the user belongs to.

Do get that id do as follows.
Go to that form's Advanced properties > More options > Form pieces and in Before Form section set Type to Custom.
In the code area below put code like this:
$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);
NOTE: The code above will fill the field named usergroupid with the usergroup id.
In case the user isn't logged in, the field would be filled with 0.

Then you would write visibility rules like this:
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

Let me know whether this worked as you wanted.

Regards,

Mihaela

Please Log in or Create an account to join the conversation.

Can I use visibility rules with user group? 1 year 7 months ago #233190

  • Topic Author
  • 5uwebsite
  • Offline
  • Senior Breezer
  • Senior Breezer
  • Posts: 126
  • Thanks: 2
Hi Mihaela,

Thank you for your response.

I have followed your instruction and added the code, please check the screenshot's link:
mrkr.io/s/5c3650dfc26e6c2e5551916a/0

Also, I rewrite the visibility rules (you gave it to me) and here is the screenshot's link:
mrkr.io/s/5c3650bfc26e6c2e55519169/0

But, when I log in one of the registered group as a Non-verified member (ID: 10) and open the form, the field "Certicated_or_show" also display at the front-end.
(It should only display "Used_or_Leased" field when a Non-verified member (ID:10) fill the form; and display "Certicated_or_show" field when Verified member (ID: 11) login in and fill the form)

*Different user groups (Non-verified member (ID:10) and Verified member (ID: 11) ) show different fields ("Used_or_Leased" field and "Certicated_or_show" field) and one field only at a time.

*The field's label is in Chinese, but the name is Certificated_or_show, please check the image:
mrkr.io/s/5c36531e4c4ef023655007e0/0

Just want to make sure the visibility rules code is in a correct order

Please Log in or Create an account to join the conversation.

Can I use visibility rules with user group? 1 year 6 months ago #233205

  • mihaela
  • Offline
  • Developer
  • Developer
  • Posts: 3128
  • Karma: 105
  • Thanks: 414
Hello again,

I understand how you want this to work.

The visibility rules I've provided should work.

Here are few things that might not be set correctly so please check the following:

1) Go to Advanced properties of the "Certicated_or_show" element and check whether you have checked the "Turn off" checkbox. Do the same for "Used_or_Leased" element.

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

Let me know whether you had everything set like that or this resolved the issue.

Regards,

Mihaela

Please Log in or Create an account to join the conversation.

Moderators: ForumSupport
Time to create page: 0.054 seconds

BreezingForms Pro 1.4.7 for WordPress Released!

Available in the membership section.

Summer Sale!

Massive discounts on all subscriptions!

Get Your Subscription Here

Quick Links

Downloads

BreezingForms

ContentBuilder

BreezingCommerce

Templates

Documentation

BreezingForms

ContentBuilder

BreezingCommerce

Apprendre BreezingForms (French Community)

Apprendre et maîtriser BreezingForms par des tutoriels et exemples, le tout en français

breezingforms.eddy-vh.com

Questions et réponses sur les forums de l'AFUJ

AFUJ

Special Offer

Summer Sale! All subscriptions at a special price!

Includes prio support, all of our current and future Joomla!® extensions and Joomla!® templates for the duration of your membership.

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!