Skip Navigation

[Resolved] Unable to store image tag in Select field Display Text Option

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

Problem: I would like to display an image for each option in a select custom field, and allow Users to click images to select options in a form input field.

Solution: There is no easy way to do this with a select field. You can use a radio field instead, and add image tags to each option in the field settings page. You must include a custom code snippet to allow HTML content here.

add_filter( 'types_sanitize_field_labels', '__return_false' );

Relevant Documentation:
https://toolset.com/errata/html-in-toolset-custom-field-labels-is-stripped-when-saving-the-fields/

This support ticket is created 3 years, 6 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 7 replies, has 2 voices.

Last updated by himanshuS 3 years, 6 months ago.

Assisted by: Christian Cox.

Author
Posts
#2039433

I have a select field with 7 options and I want to replace these options with images.

Expected behavior: the user sees 7 image cards and clicks on an image to select the image.

Based on another thread, this is possible for radio button fields with an image tag in the display text field -
1) https://toolset.com/forums/topic/add-images-to-radio-button-options/
2) https://toolset.com/forums/topic/use-images-in-cred-select-field-and-enable-click-to-select-option/

I tried the same process to replace the text with an image on the select field but the image tag does not get saved.

I then tried to make the same change on a radio field but the IMG was not saved.

<img src="<em><u>hidden link</u></em>"/>

Field I want to change: hidden link

I try to make changes by inserting the src tag:
hidden link

When I try to save the image tag in one option (consumer), the image does not get saved and the field becomes blank.

What am I missing, why is the src tag not getting saved in the display field?

If image tags cannot be saved in the display text field, what can I do to replace the select field/ radio button with images?

I am on US time so please feel free to pass this ticket to Christian.

#2039963

Hello, as of Types 3.3.4, you must include an additional custom code snippet to enable HTML content in custom field options. This solution is intended for use in radio fields:

add_filter( 'types_sanitize_field_labels', '__return_false' );

See more information about this in our erratum post:
https://toolset.com/errata/html-in-toolset-custom-field-labels-is-stripped-when-saving-the-fields/

I've updated the other relevant ticket to include this information, since others may search and find the solution there in the future.

#2039967

Chris,

Thanks a lot. Can this solution work for Select fields? If not, is there a workaround to make it work for select fields?

I have been using select fields and slugs of these fields are used in a lot of custom code to retrieve data. I would prefer to keep using a select field if possible.

Regards,
Himanshu

#2039989

No I do not expect this to work for select fields. Browsers are not required to support image tags inside HTML select options. Anything in an option tag other than "nothing" or "text" would be invalid HTML, per the spec:
https://html.spec.whatwg.org/multipage/form-elements.html#the-option-element

#2040199

There is issues with update on tickets.

I have submitted an update and it does not show up so I am going to type it again.

Can this work for Select fields? I am already using a bunch of them and calling the field slug in custom code to retrieve data.

Is there a workaround to use select fields instead of radio buttons?

#2040333

Thanks. Let me work on this using your feedback and get back to you.

#2041481

Sure, I will stand by for your update.

#2041503

It works. Thanks, Christian. My issue is resolved now.