News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Gender Mod

Started by safetythird, January 31, 2006, 03:09:59 PM

Previous topic - Next topic

safetythird

I've just upgraded from a Yabb Gold board to RC2. I'm quite impressed, great app all around.

I'm attempting to do a gender mod as was on the old Yabb board. I'd like to add the gender "Couple" as many users of my board are couples and we'd like a different gender icon.

I've searched the boards for advice but there doesn't seem to be much help on the subject. I'll list the steps I've taken and perhaps someone wilth more knowledge can point out what I'm missing.

Step1
open defualt theme/profile.template.php
around line 1415 edit so it looks like this:

<select name="gender" size="1">
<option value="0"></option>
<option value="1"', ($context['member']['gender']['name'] == 'm' ? ' selected="selected"' : ''), '>', $txt[238], '</option>
<option value="2"', ($context['member']['gender']['name'] == 'f' ? ' selected="selected"' : ''), '>', $txt[239], '</option>
<option value="3"', ($context['member']['gender']['name'] == 'c' ? ' selected="selected"' : ''), '>', $txt[6901], '</option>
</select>


Step2
open default theme/languages/index.english.php
around line 151 add

$txt[6901] = 'Couple';


Step3
Upload Couple.gif to default theme/images

Step4
open default theme ManageMembers.php
around line 186 edit so it looks like this:

<td align="left" colspan="2">
<label for="gender-0"><input type="checkbox" name="gender[]" value="0" id="gender-0" checked="checked" class="check" /> ', $txt['undefined_gender'], '</label>&nbsp;&nbsp;
<label for="gender-1"><input type="checkbox" name="gender[]" value="1" id="gender-1" checked="checked" class="check" /> ', $txt[238], '</label>&nbsp;&nbsp;
<label for="gender-2"><input type="checkbox" name="gender[]" value="2" id="gender-2" checked="checked" class="check" /> ', $txt[239], '</label>&nbsp;&nbsp;
<label for="gender-3"><input type="checkbox" name="gender[]" value="3" id="gender-3" checked="checked" class="check" /> ', $txt[6901], '</label>
</td>


This is where I'm getting stuck. The value 3 is getting inserted into the db after editting the profile but the select box defaults to Male the next time I go to edit the profile.

When viewing the profile Gender is blank (nothing output).

When viewing a post by a couple the gender icon is Female.gif.

Can someone point me to the right files I need to edit? I will post a summary for any others that want this mod.

Thanks!

safetythird

After a bit of poking around the Sources directory I may have this solved.

Edit Sources/Profile.php
around line 282 change this:

'gender' => array('name' => empty($user_profile[$memID]['gender']) ? '' : ($user_profile[$memID]['gender'] == 2 ? 'f' : 'm')),

to this:

'gender' => array('name' => empty($user_profile[$memID]['gender']) ? '' : ($user_profile[$memID]['gender'] == 1) ? 'm' : ($user_profile[$memID]['gender'] == 2) ? 'f' : ($user_profile[$memID]['gender'] == 3 ? 'c' : 'm')),


In the same file around line 2741 change this line:

'name' => empty($_POST['gender']) ? '' : ($_POST['gender'] == 2 ? 'f' : 'm')

to this:
'name' => empty($_POST['gender']) ? '' : ($_POST['gender'] == 1) ? 'm' : ($_POST['gender'] == 2) ? 'f' : ($_POST['gender'] == 3 ? 'c' : 'm')


Then edit Sources/Load.php
around line 918 change this line:

'image' => !empty($profile['gender']) ? '<img src="' . $settings['images_url'] . '/' . ($profile['gender'] == 1 ? 'Male' : 'Female') . '.gif" alt="' . $gendertxt . '" border="0" />' : ''

to this:

'image' => !empty($profile['gender']) ? '<img src="' . $settings['images_url'] . '/' . ($profile['gender'] == 1 ? 'Male' : $profile['gender'] == 3 ? 'Couple' : 'Female' ) . '.gif" alt="' . $gendertxt . '" border="0" />' : ''

Then in same file around line 872 change this line:

$gendertxt = $profile['gender'] == 2 ? $txt[239] : ($profile['gender'] == 1 ? $txt[238] : '');

to this:

$gendertxt = $profile['gender'] == 2 ? $txt[239] : $profile['gender'] == 1 ? $txt[238] : ($profile['gender'] == 3 ? $txt[6901] :'');


Seems to be working now. When viewing the profile it states Couple if that is what gender is set to. When editting the profile the gender dropdown defaults to Couple and when viewing posts the Couple icon is displayed.

If someone knows a more elegant way of writing those : expressions I'd love to see them. I'm not a developer. This hasn't been extensively tested so USE AT YOUR OWN RISK and backup your files before editing them.

I'd love to post the Couple icon (a mix of male+female) but it appears I do not have that permission.

Feedback appreciated.

Cheers!


Aquilo

I remember making a mod "Gender Based Titles Mod" for YaBBSE and the idea was not popular, there was one that goes almost back to when smf started I guess a charter member asked for it and grudge made it, but
like my old mods "I guess" when SMF advances a version and the mod is not updated it's removed to post heaven.

But there was once a mod for this
http://www.google.com/search?hl=en&lr=&safe=off&domains=simplemachines.org&q=grudge+Gender+Based+Groups&btnG=Search&sitesearch=simplemachines.org

you can download it here if you want a place to start, it works up to SMF 1.0.5!

hope this helps!!!

bbbmmm

Hey thanks for that.

I have a forum with some transgender people and some intersex people.
They want to have the option of "Other" on gender, so now I can use that coding.

clubvlive

I tried both above and no luck.

I have the same trouble as the 1st post (database getting updated, but correct gender not showing up).

Any thoughts?

NOTE: I'm currently doing this on the member edit profile page. I haven't dug into if anything would need to be changed up on registration etc....

I appreciate all responses!


BWWD2006

#5
I also tried this mod

i am setting up a site where members might be couples and wanted the option of them choosing if they were a mf couple ff couple or mm couple


i followed the above instructions from the top 2 posts and simply added in 3 extra selections instead of just one for each step

i beleive i modified everything correctly

when selecting the gender the database gets updated i have checked that and the correct number gets entered but the profile of a member does not display the right info

first off it displays Male as the gender on the profile and when editing profile the 5th option MM Couple gets displayed instead of the one whos value is stored in the database

and the image being displayed on the post is also for the mm couple

but the alt text does display male

so when the database says its got the value of MF couple but the profile shows Male and the default shows MM Couple when going to edit profile and the post image shows MM Couple

no idea why??

the only exception to this is when i chose the blank option in gender and it actually stores that as 0 and recognises no gender selected so doesnt display any image or text but why are the other options always displaying wrong

can anyone help me out

thanks

Updated Code i am using below

Profile.php
'gender' => array('name' => empty($user_profile[$memID]['gender']) ? '' : ($user_profile[$memID]['gender'] == 1 ? 'm' : $user_profile[$memID]['gender'] == 2 ? 'f' : $user_profile[$memID]['gender'] == 3 ? 'mf' : $user_profile[$memID]['gender'] == 4 ? 'ff'  : $user_profile[$memID]['gender'] == 5 ? 'mm'  : 'm')),

Load.php
'gender' => array(
'name' => $gendertxt,
'image' => !empty($profile['gender']) ? '<img src="' . $settings['images_url'] . '/' . ($profile['gender'] == 1 ? 'Male' : $profile['gender'] == 2 ? 'Female' : $profile['gender'] == 3 ? 'MaleFemale' : $profile['gender'] == 4 ? 'Female2' : $profile['gender'] == 5 ? 'Male2' : 'Female') . '.gif" alt="' . $gendertxt . '" border="0" />' : ''
),


ManageMembers.php
'gender' => array(
'db_fields' => array('gender'),
'type' => 'checkbox',
'values' => array('0', '1', '2', '3', '4', '5'),
),


ManageMembers.template.php
<label for="gender-0"><input type="checkbox" name="gender[]" value="0" id="gender-0" checked="checked" class="check" /> ', $txt['undefined_gender'], '</label>&nbsp;&nbsp;
<label for="gender-1"><input type="checkbox" name="gender[]" value="1" id="gender-1" checked="checked" class="check" /> ', $txt[238], '</label>&nbsp;&nbsp;
<label for="gender-2"><input type="checkbox" name="gender[]" value="2" id="gender-2" checked="checked" class="check" /> ', $txt[239], '</label>
<label for="gender-3"><input type="checkbox" name="gender[]" value="3" id="gender-3" checked="checked" class="check" /> ', $txt[2391], '</label>
<label for="gender-4"><input type="checkbox" name="gender[]" value="4" id="gender-4" checked="checked" class="check" /> ', $txt[2392], '</label>
<label for="gender-5"><input type="checkbox" name="gender[]" value="5" id="gender-5" checked="checked" class="check" /> ', $txt[2393], '</label>


index.english.php
$txt[238] = 'Male';
$txt[239] = 'Female';
$txt[2391] = 'Couple M/F';
$txt[2392] = 'Couple F/F';
$txt[2393] = 'Couple M/M';


Profile.template.php
<option value="0"></option>
<option value="1"', ($context['member']['gender']['name'] == 'm' ? ' selected="selected"' : ''), '>', $txt[238], '</option>
<option value="2"', ($context['member']['gender']['name'] == 'f' ? ' selected="selected"' : ''), '>', $txt[239], '</option>
<option value="3"', ($context['member']['gender']['name'] == 'mf' ? ' selected="selected"' : ''), '>', $txt[2391], '</option>
<option value="4"', ($context['member']['gender']['name'] == 'ff' ? ' selected="selected"' : ''), '>', $txt[2392], '</option>
<option value="5"', ($context['member']['gender']['name'] == 'mm' ? ' selected="selected"' : ''), '>', $txt[2393], '</option>


i thinks thats everything i modified and i uploaded the new images to the images folder with the names as defined in the code in Load.php

BWWD2006

update after a bit more testing and still no solution found

i have noticed on the Load.php page and in the Profile.php

the last item in the code eg $profile['gender'] == 5 ? 'Male2' is what it is defaulting to for some reason so what ever i have set in code as the last item in the list it uses that value to display the gender in the profile and to choose the image for posts

now why it is doing that instead of  checking whcih one is set in the database and picking the correct one according to that i dont know


BWWD2006


bbbmmm

#8
Here's the code I changed on my site to add an "Other" gender...

<edit file>
Themes/default/languages/Modifications.english.php
</edit file>

<search for>
$txt[239] = 'Female';
</search for>

<add after>
$txt['gender_other'] = 'Other';
</add after>

<edit file>
Sources/Profile.php
</edit file>

<search for>
'gender' => array('name' => empty($user_profile[$memID]['gender']) ? '' : ($user_profile[$memID]['gender'] == 2 ?  'f' : 'm')),

</search for>

<replace>
'gender' => array('name' => empty($user_profile[$memID]['gender']) ? '' : ($user_profile[$memID]['gender'] == 1) ? 'm' : ($user_profile[$memID]['gender'] == 2) ? 'f' : ($user_profile[$memID]['gender'] == 3 ? 'o' : 'm')),

</replace>

<search for>
'name' => empty($_POST['gender']) ? '' : ($_POST['gender'] == 2 ? 'f' : 'm')
</search for>

<replace>
'name' => empty($_POST['gender']) ? '' : ($_POST['gender'] == 1) ? 'm' : ($_POST['gender'] == 2) ? 'f' : ($_POST['gender'] == 3 ? 'o' : 'm')
</replace>

<edit file>
Sources/Load.php
</edit file>

<search for>
'image' => !empty($profile['gender']) ? '<img src="' . $settings['images_url'] . '/' . ($profile['gender'] == 1 ? 'Male' : 'Female') . '.gif" alt="' . $gendertxt . '" border="0" />' : ''
</search for>

<replace>
'image' => !empty($profile['gender']) ? '<img src="' . $settings['images_url'] . '/' . ($profile['gender'] == 1 ? 'Male' : $profile['gender'] == 3 ? 'Other' : 'Female' ) . '.gif" alt="' . $gendertxt . '" border="0" />' : ''

</replace>

<search for>
$gendertxt = $profile['gender'] == 2 ? $txt[239] : ($profile['gender'] == 1 ? $txt[238] : '');

</search for>

<replace>
$gendertxt =  $profile['gender'] == 1 ? $txt[238] : ($profile['gender'] == 2 ? $txt[239] : ($profile['gender'] == 3 ? $txt['gender_other'] :''));

</replace>


<edit file>
Sources/ManageMembers.php
</edit file>

<search for>

'gender' => array(
'db_fields' => array('gender'),
'type' => 'checkbox',
'values' => array('0', '1', '2'),

</search for>

<replace>

'gender' => array(
'db_fields' => array('gender'),
'type' => 'checkbox',
'values' => array('0', '1', '2','3'),

</replace>


<edit file>
Themes/default/ManageMembers.template.php
</edit file>

<search for>

label for="gender-2"><input type="checkbox" name="gender[]" value="2" id="gender-2" checked="checked" class="check" /> ', $txt[239], '</label>

</search for>

<add after>
&nbsp;&nbsp;
<label for="gender-3"><input type="checkbox" name="gender[]" value="3" id="gender-3" checked="checked" class="check" /> ', $txt['gender_other'], '</label>

</add after>


<edit file>
Themes/default/Profile.template.php
</edit file>

<search for>
<option value="2"', ($context['member']['gender']['name'] == 'f' ? ' selected="selected"' : ''), '>', $txt[239], '</option>

</search for>

<add after>
<option value="3"', ($context['member']['gender']['name'] == 'o' ? ' selected="selected"' : ''), '>', $txt['gender_other'], '</option>

</add after>


I had a lot of problems selecting genders until I fixed the $gendertxt in the Load.php as above.


BWWD2006

thanks ill try that out sometime soon

bbbmmm

In Sources/Profile.php the code should actually be....


'gender' => array('name' => empty($user_profile[$memID]['gender']) ? '' : ($user_profile[$memID]['gender'] == 1 ? 'm' : ($user_profile[$memID]['gender'] == 2 ? 'f' : ($user_profile[$memID]['gender'] == 3 ? 'o' : '')))),



'name' => empty($_POST['gender']) ? '' : ($_POST['gender'] == 1 ? 'm' : ($_POST['gender'] == 2 ? 'f' : ($_POST['gender'] == 3 ? 'o' : '')))


Because that will make the "or" signs function correctly. Without it there's a problem where... once you change gender to female, then go back and look at the gender it is male, but not actually stored as male - just appears as such in the profile, and vice versa with male/female.

MSport

bbbmmm,

Thank you very much for supplying the code changes! Works great!  All except one item -- the images.

I made the changes to Load.php as you specified, and added a third gender image (Other.gif).  Except now, all "male" members have the "other" gender image!  The "female" image works fine, it's just that both "male" and "other" genders both point to the "other" image.

Can you please supply corrected code for this?

Thanks again!

BWWD2006

got that working sort of but i would like to not only add 1 extra option to the geneder selection but i would like 3 extra ones

male, female, mf couple, ff couple, mm couple but when i try modifiying it and adding mo genders i dont seem to be getting it right not sure where to put the extra 2 genders into all the changes you made above  

perplexed

you could forget about checking the male/female gender option altogether and add a custom profile field with a selection box, adding as many options as you want

BWWD2006

but then i would have to make a new method of checking and displaying a gender image too


BWWD2006

well if i wanted to use a different method of displaying the gender text rather than just modifying whats already there i  would still have the problem with the gender image not being right and would have to modify that or create a new bit of code to display the correct image

really all i need is the code above but set up correctly to use 5 different gender options and gender images instead of only 3 but at the moment i have had no luck figuring out adding the extra two options without crashing the whole thing and making it not work


BWWD2006

well at the moment there is a section of script which checks what gender someone is based on the section of script that deals with gender and that script determind what image to display male or female but if i were to use a completely different method of selecting and displaying gender i would also have to modify how the image is selected if i wasnt using the standard drop down selection for gender and created a new dropdown box instead

like i mentioned the above code workd fine from what i have seen but there isnt enough gender options and i cannot add the exttra without messing it up ad im not sure what im doing

MSport

Help Please!

I followed the method of adding another gender by bbbmmm above.  Works great except for the image handling in Load.php (see my first request above).

I made the changes to Load.php as specified, and added a third gender image (Other.gif).  Except now, all "male" members have the "other" gender image!  The "female" image works fine, it's just that both "male" and "other" genders both point to the "other" image.

In Load.php, here is the changed code that isn't working:

'image' => !empty($profile['gender']) ? '<img src="' . $settings['images_url'] . '/' . ($profile['gender'] == 1 ? 'Male' : $profile['gender'] == 3 ? 'Other' : 'Female' ) . '.gif" alt="' . $gendertxt . '" border="0" />' : ''

I've tried several different things including:

'image' => !empty($profile['gender']) ? '<img src="' . $settings['images_url'] . '/' . ($profile['gender'] == 1 ? 'Male' : $profile['gender'] == 2 ? 'Female' : $profile['gender'] == 3 ? 'Other' ) . '.gif" alt="' . $gendertxt . '" border="0" />' : ''

In almost every instance I get the following error:

Parse error: parse error, unexpected ')' in . . . . /Sources/Load.php on line 1026

More than likely something simple, but I just can't find it!  Please help!

Thanks in advance.

Advertisement: