Skip Navigation

[Resolved] Result of checkboxes and css in a shortcode

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

Problem: I would like to display a different flag icon for each checked checkbox in a checkboxes group.

Solution: Use the Types field shortcode with "state" and "option" attributes to display different HTML for each checked checkbox.

[types field='documentation-language' state="checked" option="0"]<span class="flag-icon flag-icon-cn"></span>[/types][types field='documentation-language' state="checked" option="1"]<span class="flag-icon flag-icon-fr"></span>[/types]

Relevant Documentation:
https://toolset.com/documentation/customizing-sites-using-php/functions/

This support ticket is created 4 years, 9 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 8 replies, has 2 voices.

Last updated by ericK-4 4 years, 9 months ago.

Assisted by: Christian Cox.

Author
Posts
#1577165

Hi,
I develop a pdf directory and in the backend my client can choose the language with checkboxes : french, english and so on.
On the front end, I want a little flag appears to show the language. I use flag icon css
In custom fields checkboxes, I put each code of the country in each
France : flag-icon-fr
English : flag-icon-gb

I make a list to separate each flag for the front end :

  • [types field='documentation-language' separator='
  • '][/types]

But how can I insert the shortcode in the CSS so that toolset return this result in frontend like this
<span class="flag-icon flag-icon-fr"></span>

Thanks

#1577693

Hi, what if more than one checkbox is selected, can you show what you expect? Will you display separate spans for each flat, or will you include multiple classes in the same span? I'm not clear from your example how that will be handled.

#1578221
flag-screen.png

Hi,
I make a screenshot of my views and what appears for the moment in front end
Hoping that helps

#1578655

Okay I see how it works now, but what I want to know is how it should work with the span and CSS classes. Do you want separate spans like this:

<span class="flag-icon flag-icon-fr"></span>
<span class="flag-icon flag-icon-gb"></span>

...or do you want it to be combined in one span like this:

<span class="flag-icon flag-icon-fr flag-icon-gb"></span>

Which one is correct?

#1578755

Hi,
I choose checkboxes because the documentation can exist in several languages. So in front end it is a list like this where XX is the abbreviation of the country in flag-icon-XX I put as value in checkboxes

<span class="flag-icon flag-icon-fr"></span>
<span class="flag-icon flag-icon-gb"></span>

Thanks

#1578841

There's not really an easy way to produce complex HTML like this using a single shortcode. It requires you use a fairly complex conditional for each country. For example:

[wpv-conditional if="( CONTAINS(ARRAY($(wpcf-document-language)), 'fr') )"]
<span class="flag-icon flag-icon-fr"></span>
[/wpv-conditional]
[wpv-conditional if="( CONTAINS(ARRAY($(wpcf-document-language)), 'gb') )"]
<span class="flag-icon flag-icon-gb"></span>
[/wpv-conditional]

You must create a conditional for each possible checkbox.

#1579507
Capture d’écran 2020-04-09 à 09.50.30.png

Hi Christian,

I try you code and it returns nothing. I correct the slug by the good one -> documentation-language
I made a screenshot to show you the setting of my checkboxes if it helps
Thanks

#1583065

It looks okay here, but I would remove "gb" from the "Not selected" field. May I log into wp-admin to see the problem? Where can I see the conditional code on the front-end of your site? I have enabled private reply fields here.

#1584115

I made this and it works now :
<div class="notice-flag">
[types field='documentation-language' state="checked" option="0"]<span class="flag-icon flag-icon-cn"></span>[/types][types field='documentation-language' state="checked" option="1"]<span class="flag-icon flag-icon-fr"></span>[/types][types field='documentation-language' state="checked" option="2"]<span class="flag-icon flag-icon-de"></span>[/types][types field='documentation-language' state="checked" option="3"]<span class="flag-icon flag-icon-it"></span>[/types][types field='documentation-language' state="checked" option="4"]<span class="flag-icon flag-icon-nl"></span>[/types][types field='documentation-language' state="checked" option="5"]<span class="flag-icon flag-icon-no"></span>[/types][types field='documentation-language' state="checked" option="6"]<span class="flag-icon flag-icon-ru"></span>[/types][types field='documentation-language' state="checked" option="7"]<span class="flag-icon flag-icon-es"></span>[/types][types field='documentation-language' state="checked" option="8"]<span class="flag-icon flag-icon-gb"></span>[/types]
</div>