Skip Navigation

[Resolved] Using form's conditional group with user role

This support ticket is created 4 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 5 replies, has 2 voices.

Last updated by timH-8 4 years ago.

Assisted by: Waqar.

Author
Posts
#1569005

I can't get a conditional field group logic to work on a CRED form.

I have written this code:
[cred_show_group if="(USER(‘role’) eq ‘administrator’)" mode="fade-slide"]
Privacy

[cred_field field='privacy' force_type='taxonomy' output='bootstrap' display='select' single_select='true']

[/cred_show_group]

What I want to have happen is when the current logged-in user has role = administrator, then the field inside the group will show.

#1569037

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Tim,

Thank you for waiting.

The "cred_show_group" shortcode is designed to work with conditions based on the data in the form's fields.

To conditionally include/exclude a field based on a user's role, you can use conditional display shortcode "wpv-conditional", instead.
( ref: https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/using-shortcodes-in-conditions/ )

Example:


[wpv-conditional if="( '[wpv-current-user info="role"]' eq 'administrator' )"]

[cred_field field='privacy' force_type='taxonomy' output='bootstrap' display='select' single_select='true']

[/wpv-conditional]

This will show the enclosed field, only when the current user's role is "administrator".
( ref: https://toolset.com/documentation/user-guides/views/views-shortcodes/#wpv-current-user )

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#1571389

This is great - thank you. However it does not appear to work with custom user roles I create through Toolset Access? I have created a role "Member".

#1571395

Also, what if I wanted a condition that would display for a user if they were in x-role OR y-role? Appreciate your support. I've been able to build something quite amazing with Toolset; great success story for your plugin. Almost there!!

#1573243

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Tim,

Thank you for waiting.

I've performed several tests on my website, but couldn't reproduce this issue of the conditional display not working for the custom user roles.

Have you tried to see the output of shortcode [wpv-current-user info="role"] directly, in the form's editor?

Please test this shortcode as it is, while logged in as a user with "Member" role and see what is returned.
( you'll probably see "member" )

After that, please make sure you're using that same output for the comparison in the conditional block:

Example:


[wpv-conditional if="( '[wpv-current-user info="role"]' eq 'member' )"]
 
[cred_field field='privacy' force_type='taxonomy' output='bootstrap' display='select' single_select='true']
 
[/wpv-conditional]

In case, the issue still persists, you're welcome to share temporary admin login details, for the website so that I can see how everything is set up.

Please also include the link to the page with this form and the login details for a user with the "Member" role that you're testing this with.

Note: Your next reply will be private and please make a complete backup copy, before sharing the access details.

As for your question about combining conditions to check for more than one role, yes that is possible too.
( ref: https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/nesting-and-combining-conditions/ )

Suppose you'd like to show a field only to "Administrator" or "Member" roles. The combined conditional block will look like this:


[wpv-conditional if="( '[wpv-current-user info="role"]' eq 'administrator' ) OR ( '[wpv-current-user info="role"]' eq 'member' )"]
 
[cred_field field='privacy' force_type='taxonomy' output='bootstrap' display='select' single_select='true']
 
[/wpv-conditional]

regards,
Waqar

#1573683

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.