Skip Navigation

[Resolved] Toolset Forms conditional on Taxonomy input 

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

Problem:
We want to display fields or content conditionally to the taxonomy term chosen in a Toolset Form.
How can we achieve that?

Note, the final goal may also be to just ensure the user chooses at least one term.

Solution:
You can, for example, hide the Submit button, if the taxonomy value isn't checked or even, a specific option:
https://toolset.com/forums/topic/conditional-display-based-on-taxonomy-selection-in-a-cred-form/

With this same method, you can also display messages or other fields depending on what term is chosen.
Note, this works only for hierarchical terms, not for flat terms like tags

This support ticket is created 5 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 2 replies, has 2 voices.

Last updated by stevenT-5 5 years ago.

Assisted by: Beda.

Author
Posts
#1465449

Hi,
Let's say I have a form that includes a taxonomy field (check boxes of options like Red, Blue, Green.) There's a chance the users miss checking a box when submitting the form.

So when I display this taxonomy value on a template, I want to show a field label only if there's a selected option by the user like so – Color: Red. In this case, I need to conditionally display the field label. How do I set display condition on the template?

If in the case I can't conditionally check for selected option to display the label, then the second idea is to have a default selection of option. If user didn't check the box, the default selection is None. So I can display this on my template like so – Color: None. How do I set a default option for taxonomy field?

Thank you.

#1465657

You have a third option:
Ensure the user selects an option on the Form already.

I elaborate on this approach here:
https://toolset.com/forums/topic/conditional-display-based-on-taxonomy-selection-in-a-cred-form/
With this approach you can, for example, hide the Submit button, if the taxonomy value isn't checked or even, a specific option.

Related to ensure there is data when you display it, this is always a good idea as well.
You can do that with HTML conditionals in the Template you display the Taxonomy chosen.
Those are explained here:
https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/

For Taxonomies, you'd have to use this syntax:
https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/displaying-taxonomies-conditionally/

There are ways to check if the post you display has any term of a taxonomy assigned (hence "is not empty"):
https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/displaying-taxonomies-conditionally/#one

But also, to check the specific term assigned:
https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/displaying-taxonomies-conditionally/#specific

This allows you to output any text, such as labels, conditionally to whether there is such term or not.

#1470399

Thanks for the reply, Beda. What you have above are the solutions I was looking for. I'll look into the details and determine which will work best for me. Again, thank you for the quick help.