Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: vroony on July 23, 2015, 05:23:09 AM

Title: Displaying gender in the form of icons instead of words
Post by: vroony on July 23, 2015, 05:23:09 AM
I've created a custom field to allow the user to select gender from a radio button selection while making a profile:

(https://imgur.com/5PCWBPV)

But when I view this on someone's profile, I want it to show the images male.png or female.png (depending on the user's choice, of course) instead of the text "male" or "female". How can I do this?

NOTE:I'm aware there is a built-in gender field, but I don't want to use that for... reasons of my own...which I'd rather not disclose. Please understand.
Title: Re: Displaying gender in the form of icons instead of words
Post by: Illori on July 23, 2015, 05:51:41 AM
do you have anything in the Show Enclosed Within Text (Optional): field? if so what? without something there no image will show at all.
Title: Re: Displaying gender in the form of icons instead of words
Post by: margarett on July 23, 2015, 06:47:21 AM
In radio buttons (and others) no HTML is allowed (for security reasons), neither BBC is parsed unfortunately.

This has been discussed before (several times actually) and I don't think it can be changed :(

edit: actually I think I found a "manual" way. It will break if you edit the field again but if not it should work. Give me some minutes
Title: Re: Displaying gender in the form of icons instead of words
Post by: vroony on July 23, 2015, 06:55:48 AM
Quote from: Illori on July 23, 2015, 05:51:41 AM
do you have anything in the Show Enclosed Within Text (Optional): field? if so what? without something there no image will show at all.

I'm not exactly sure what I should put to achieve what I want, so I put this...


<img src="mysiteurl.com/male.png">
<img src="mysiteurl.com/female.png">


This obviously made both images show up. I want it to vary depending on what the user chooses?
Title: Re: Displaying gender in the form of icons instead of words
Post by: vroony on July 23, 2015, 06:56:48 AM
Quote from: margarett on July 23, 2015, 06:47:21 AM
In radio buttons (and others) no HTML is allowed (for security reasons), neither BBC is parsed unfortunately.

This has been discussed before (several times actually) and I don't think it can be changed :(

edit: actually I think I found a "manual" way. It will break if you edit the field again but if not it should work. Give me some minutes

Whew... I was pretty crestfallen for a moment,,  :D
Title: Re: Displaying gender in the form of icons instead of words
Post by: margarett on July 23, 2015, 07:19:01 AM
OK, we can try this.

I created a custom profile field, radio button, as attached.

The options are links to images (each option a link), eg:
<img src="http://localhost/male.png">
<img src="http://localhost/female.png">


When you submit this, SMF will sanitize the HTML input, by replacing every HTML character with its "textual" equivalent: "<" becomes "&lt;" and so on. So when I look at my table "smf_custom_fields" table, column "field_options", I find this
&lt;img src=&quot;http://localhost/male.png&quot;&gt;,&lt;img src=&quot;http://localhost/female.png&quot;&gt;
So you see both radio options separated by a comma and all html delimiters replaced with literal characters. If I change that to valid HTML, eg:
<img src="http://localhost/male.png">,<img src="http://localhost/female.png">
It actually works. In my profile I can choose by image an not just by text anymore. And it also shows correctly in the mini-profile (topic view)

If you go back to edit the profile field this will be reverted, though...
Title: Re: Displaying gender in the form of icons instead of words
Post by: Illori on July 23, 2015, 07:21:31 AM
dont you need to use {{INPUT}} somewhere so it just shows one of the 2 images depending on the input selected?
Title: Re: Displaying gender in the form of icons instead of words
Post by: margarett on July 23, 2015, 07:23:21 AM
In all honesty... I have no idea how that works :P
(my bad, of course...)
Title: Re: Displaying gender in the form of icons instead of words
Post by: Illori on July 23, 2015, 07:25:16 AM
does http://smfhelp.org/index.php?page=Advanced-Profile-Fields help you any?
Title: Re: Displaying gender in the form of icons instead of words
Post by: margarett on July 23, 2015, 07:30:00 AM
I will look at it, thanks. Who knows maybe there is a easier way ;) (although I would suggest that it should have been said before and I couldn't find it...)
Title: Re: Displaying gender in the form of icons instead of words
Post by: Illori on July 23, 2015, 07:32:28 AM
i dont see why it would not work if you put <img src="http://localhost/{{input}}.png"> in the field and left it at that... i dont know why your install was giving you issues with the html in that box i have not seen that before.
Title: Re: Displaying gender in the form of icons instead of words
Post by: vroony on July 24, 2015, 02:19:34 AM
Quote from: Illori on July 23, 2015, 07:32:28 AM
i dont see why it would not work if you put <img src="http://localhost/{{input}}.png"> in the field and left it at that... i dont know why your install was giving you issues with the html in that box i have not seen that before.

before I try margarett's method, I want to try yours since it looks simpler, and frankly, less scary  ;D

But, I'm not sure how that's supposed to work? Does the image's name have to be the same name as the input? Whatever, I'll give it a go...
Title: Re: Displaying gender in the form of icons instead of words
Post by: Illori on July 24, 2015, 05:13:36 AM
yes it has to be the same as the options that the user can select.

but it should be {INPUT} not {{INPUT}}
Title: Re: Displaying gender in the form of icons instead of words
Post by: vroony on July 27, 2015, 04:24:34 AM
Seems like I left the thread to die...
Well, I've tried everything I could, it's just not working. I renamed my images male.png and female.png and tried the suggested option, but the image isn't displaying...
Title: Re: Displaying gender in the form of icons instead of words
Post by: Illori on July 27, 2015, 05:05:55 AM
can you take a screenshot of the config you have for the profile field in the admin panel?
Title: Re: Displaying gender in the form of icons instead of words
Post by: vroony on July 28, 2015, 05:17:44 AM
Never mind. It was some dumb spelling error. Thanks for all the help!