Skip Navigation

[Resolved] conditional display form field group – what exactly do I put in the condition?

This thread is resolved. Here is a description of the problem and solution.

Problem:
conditional display form field group - what exactly do I put in the condition?

Solution:

You can find proposed solution, in this case with the following reply:
https://toolset.com/forums/topic/conditional-display-form-field-group-what-exactly-do-i-put-in-the-condition/#post-2236043

Relevant Documentation:

This support ticket is created 3 years, 7 months 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 7 replies, has 2 voices.

Last updated by gabrieleB 3 years, 7 months ago.

Assisted by: Minesh.

Author
Posts
#2235717
Bildschirmfoto 2021-12-03 um 04.44.58.png

I want to insert a conditional group into a form, only to be seen by administrators.

I already found a thread dealing with this topic (https://toolset.com/forums/topic/conditionally-display-form-field-group/), where the suggested solution is to use this condition:

[wpv-conditional if="( '[wpv-current-user info="role"]' eq 'administrator' ) "]
<!-- content to be shown only when this is true inside here -->
[/wpv-conditional]

My question now is: What code exactly do I paste into the conditional box?
Or: Where do I find the code to put INTO the condition, in the middle.
If I only put in the code above (see screenshot in attachment) it's not working.

I'm sorry, I'm not super-experienced in programming and would appreciate a helping hand here.
Many thanks
Gabriele

#2235877

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

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

To conditionally show/hide the form field based on a user's role, you can use conditional shortcode [wpv-conditional] that is you are currently trying to use:
=> https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/using-shortcodes-in-conditions/

What you should do is:
- Switch to Expert Mode of your form
- And then add the conditional shortcode and adjust it as per your requirement and save the form

#2236017

Ok, If I understood you correctly, I take this piece of code and put something in the middle. But where do I find the code to put in the middle?

[wpv-conditional if="( '[wpv-current-user info="role"]' eq 'administrator' ) "]
<!-- where do I find the code to put into here? -->
[/wpv-conditional]

?
Sorry, I don't get it.

Could you maybe provide me with an example of such an edited piece of code that goes into there?

#2236043

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

As you can see with the following image - there is a option "Expert mode" available at top right corner, you should activate it and you will be able to edit/build your form manually. There within the form's editor you should add the conditional statement and wrap your field with this conditional statement.
=> hidden link

#2236127

Got it! And it's working! Thank you so much for your patience, providing a picture and explaining until I got onto the right path. I'm happy this problem is resolved now. Thank you!

#2236161
conditional-group-4.png
conditional-group-3.png
conditional-group-2.png
conditional-group-1.png

I thought I'd do a little follow-up and explain the solution in more detail, for those like me who are not fluent programmers:

When you have a conditional fieldgroup like this (pic. 1) klick down and choose the method of appearance of your choice (pic. 2). DON'T "edit conditions manually", you have to enter the code elsewhere. Click "ok" to close this little window. Scroll up to the button "expert mode" on the right side, just under the heading "form editor", like described above. You are warned, that "changes that you make in the HTML editor will be lost if you switch back to the Visual editor", which is correct. (Been there, done that.) So make sure your form is finished or be prepared to build the conditional fieldgroup again, if you have to make additional changes to the form in the visual editor. Scroll down until you reach "cred_show_group" which marks the beginning of the conditional part (pic. 3). Replace the opening part with your desired opening part (in my case: [wpv-conditional if="( '[wpv-current-user info="role"]' eq 'administrator' ) "] ) (pic. 4), and further down replace the closing "[/cred_show_group]" with your closing"[/wpv-conditional]". Save the form and you're good to go.
Note that if you switch back to the visual editor, the conditional part will be lost and you will have to build it again.

#2236195
conditional-group-1.jpg
conditional-group-2.jpg
conditional-group-3.jpg
conditional-group-4.jpg

I thought I'd do a little follow-up and explain the solution in more detail, for those like me who are not fluent programmers:

When you have a conditional fieldgroup like this (pic. 1) klick down and choose the method of appearance of your choice (pic. 2). DON'T "edit conditions manually", you have to enter the code elsewhere. Click "ok" to close this little window. Scroll up to the button "expert mode" on the right side, just under the heading "form editor", like described above. You are warned, that "changes that you make in the HTML editor will be lost if you switch back to the Visual editor", which is correct. (Been there, done that.) So make sure your form is finished or be prepared to build the conditional fieldgroup again, if you have to make additional changes to the form in the visual editor.

Scroll down until you reach "cred_show_group" which marks the beginning of the conditional part (pic. 3). Replace the opening part with your desired opening part (in my case: [wpv-conditional if="( '[wpv-current-user info="role"]' eq 'administrator' ) "] ) (pic. 4), and further down replace the closing "[/cred_show_group]" with your closing"[/wpv-conditional]". Save the form and you're good to go.

Note that if you switch back to the visual editor, the conditional part will be lost and you will have to build it again.

#2236263

My issue is resolved now. Thank you!