Skip Navigation

[Resolved] Bad display of checkboxes with HTML in the values.

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

Problem:
Customer was having troubles trying to add html code to the checkbox title.
Solution:
I checked it and the issue was that both title and value fields had html code, I made an example where adding the code only to the title worked as expected, I offered this solution and the customer said it sufficed for him.
Relevant Documentation:
https://toolset.com/errata/html-in-toolset-custom-field-labels-is-stripped-when-saving-the-fields/

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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Sao_Paulo (GMT-03:00)

This topic contains 6 replies, has 2 voices.

Last updated by Mateus Getulio 8 months, 3 weeks ago.

Assisted by: Mateus Getulio.

Author
Posts
#2685357
Screenshot 2024-02-26 at 19.50.18.png

Hi

I used this script to add html to the values of my checkboxes to ba able to have icons instead of text:

<?php /** * Deactivate the sanitization of custom field and field option labels, * so that they can contain HTML code. * * Note that this is not recommended for sites that don't explicitly need it. * Disabling sanitization can have undesired security or other ramifications. */ toolset_snippet_security_check() or die( 'Direct access is not allowed' ); // Put the code of your snippet below this comment. add_filter( 'types_sanitize_field_labels', '__return_false' );

However, when I add the checkboxes field in a form, I have code displaying in a unordered list of options.

Is it a bug or there's a solution to avoid that ?

#2685368

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello there,

Can you check if you added the script in Toolset > Custom Code and that the script status is 'active'? (Default is inactive)

If so, please try to add the fields values again to see if the HTML will stick this time.

Thank you, please let us know.

#2685438

Hi Mateus,

Unfortunately it is active and when I deleted the options and recreate them, I have the same result...

#2685478

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello,

I would like to request temporary access (wp-admin and FTP) to your site to take better look at the issue. You will find the needed fields for this below the comment area when you log in to leave your next reply. The information you will enter is private which means only you and I can see and have access to it.

Our Debugging Procedures

I will be checking various settings in the backend to see if the issue can be resolved. Although I won't be making changes that affect the live site, it is still good practice to backup the site before providing us access. In the event that we do need to debug the site further, I will duplicate the site and work in a separate, local development environment to avoid affecting the live site.

Privacy and Security Policy

We have strict policies regarding privacy and access to your information. Please see:
https://toolset.com/purchase/support-policy/privacy-and-security-when-providing-debug-information-for-support/

**IMPORTANT**

- Please make a backup of site files and database before providing us access.
- If you do not see the wp-admin/FTP fields this means your post & website login details will be made PUBLIC. DO NOT post your website details unless you see the required wp-admin/FTP fields. If you do not, please ask me to enable the private box. The private box looks like this: hidden link

Please, let me know if you need any additional details. Have a nice day.

#2685504

Unfortunately I'm working locally with Mamp Pro.

I tried on another clean installation and I still have the same result :"" class="wpt-form-checkbox form-checkbox checkbox" />" before the image I use instead of text.

This is the title of my option in the checkboxes field:
<img src="/wp-content/uploads/2024/02/kw-violence.svg" style="height:30px;width:30px;">

And the Value to store:
<img src="/wp-content/uploads/2024/02/kw-violence.svg" class="kw-icons">

Is it helping ?

#2685592

Actually the issue comes from the value of the field.
When I give a value like "good" then in the front-end form it displays correctly the icon, but on the front-end View it displays of course its value, so "good" instead of the icon.
I'd like to display the corresponding icon, so... the label ? is it possible ?

#2685628

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

form.png

Hello there,

Please check this sandbox I created to demonstrate the title working with html code: hidden link

Login link to sandbox in case you need to consult or edit something in the sandbox for me to see it: hidden link

Please check the screenshot, the title is displaying an image in the front end similar to what you want to accomplish, and in the value I stored only the image link instead of the full html code.

With regard to the value, is there a specific application for storing the full html, wouldn't it suffice for you to maybe store the icon/image url and then work with the link later in the site?

Thank you, please let us know.

#2685821

Of course the needed url would be enough... !
Thanks for your lights !