PDA

View Full Version : How to: Input gender as a text field


Dinocanid
09-16-2016, 09:42 PM
I've ran a forum or two in the past and someone who doesn't identify as male or female might not want to just have a simple "other" sitting on their profile. Some didn't even want to sign up because of it. So I went in to do a bit of editing and was able to make it so people could type in the gender themselves, rather than choosing an option.
(TL;DR: This changes the gender option from a radio button to a TextField. I use public_html, so if you don't then just follow from wherever you have Mysidia installed)

Step 1 (The only step)
Go to public_html/view/accountview. See this whole block?:


$profileForm->add(new Comment("Gender: "));

$genderList = new RadioList("gender");
$genderList->add(new RadioButton("Male", "gender", "male"));
$genderList->add(new RadioButton("Female", "gender", "female"));
$genderList->add(new RadioButton("Unknown", "gender", "unknown"));
$genderList->check($profile->getGender());

$profileForm->add($genderList);


Replace it with:

$profileForm->add(new Comment("Gender: ", FALSE));
$profileForm->add(new TextField("gender", $profile->getGender()));

(Optional) Step 2
Now go to phpMyAdmin and find prefix_users_profile. Change the varchar on gender from 10 to 20, just in case there isn't enough space.

Save and that's it. Pretty basic. I plan to do more tutorials in the future once I figure more stuff out.

parayna
09-19-2016, 05:51 AM
This is a good idea, but you might also want to change the 'register' file too! That way they can do it straight away, instead of having to go and edit their profile after sign up ^_^ (Or at least that's what I am doing XD)

Thanks for the tip off, though. I think it's a great idea :3 Definitely shows you're/your site is more inclusive!

Hall of Famer
09-19-2016, 10:03 AM
Interesting tutorial, but I wonder what is the use case of having gender as text field rather than radio button list. To my understanding genders are fixed constants, not like your name and age which can vary greatly. If you dont like 'other', you can change it to 'unknown' or 'unspecified' anyway.

Dinocanid
09-19-2016, 06:59 PM
Parayna - I actually forgot about editing the register file! I opened it up too when I was editing; I guess it slipped my mind somehow.

HoF - I was originally going to keep the radio list and just add options for a few common gender identities (besides male and female, like nonbinary, bigender, the list goes on and on) people might have; but then there's the chance that someone's identity isn't on the list, in which I would still need to keep "other"/"unknown" anyway and it kind of defeated the purpose of editing the script in the first place. So basically I came up with this to completely avoid any issues it might cause further down the line, if there happen to be any at all.

Eagle9615
09-26-2016, 06:06 PM
This is such a small fix that will mean a lot to some people, thank you for posting this!

Abronsyth
09-28-2016, 07:32 AM
This is great! Will make many users so much more comfortable! I know of people who will not even sign up on a website because of the discomfort it causes if they have to choose from a set list of genders, so this will really help that!

Dinocanid
09-28-2016, 07:24 PM
Thanks for all the input! I went in to see if I could change the register file too. It's a bit untested, since I haven't set up a new account on my site to see if it works, but I shouldn't cause any errors. Let me know if it does!

Under registerview.php, find these lines (should be 45-53):
$additionalField->add(new Comment("Gender: ", FALSE, "b"));
$additionalField->add(new Comment("Male, Female or Not specified"));

$genderList = new RadioList("gender");
$genderList->add(new RadioButton("Male", "gender", "male"));
$genderList->add(new RadioButton("Female", "gender", "female"));
$genderList->add(new RadioButton("Unknown", "gender", "unknown"));
$genderList->check("unknown");
$additionalField->add($genderList);

and replace it all with this:

$additionalField->add(new Comment("Gender: ", FALSE, "b"));
$additionalField->add(new TextField("gender"));

Pen
07-18-2020, 06:45 PM
worked beautifully! As a trans person with many diversely gendered friends I really appreciate this one