XF 1.1 Remove gender from Account Personal Details unless Unspecified

Mouth

Well-known member
I'd like to remove gender from /account/personal-details , unless the user has Unspecified and require them to set Male or Female.

The object being they set a gender if they do not have one, but once they have one they cannot change it.

Following the example at http://xenforo.com/community/threads/change-default-gender-in-registration-page.14944/ I have update to the following code in personal_details template:

Code:
<xen:if is="!{$visitor.gender}">
        <dl class="ctrlUnit">
            <dt><label>{xen:phrase gender}:</label></dt>
            <dd>
                <ul>
                    <li><label for="ctrl_gender_male"><input type="radio" name="gender" value="male" id="ctrl_gender_male" {xen:checked "{$visitor.gender} == 'male' OR !{$visitor.gender}"} /> {xen:phrase male}</label></li>
                    <li><label for="ctrl_gender_female"><input type="radio" name="gender" value="female" id="ctrl_gender_female" {xen:checked "{$visitor.gender} == 'female'"} /> {xen:phrase female}</label></li>
<xen:comment>
                    <li><label for="ctrl_gender_"><input type="radio" name="gender" value="" id="ctrl_gender_" /> ({xen:phrase unspecified})</label></li>
</xen:comment>
                </ul>
            </dd>
        </dl>
</xen:if>

This appears to work well, with the page showing no options for gender if the user already has a Male|Female gender. If the user has Unspecified, the Male|Female radio buttons are showed and Male is defaulted.

BUT, if the user has a gender set (Male or Female) and visits their /account/personal-details page (and no gender details/radio-buttons are shown), when clicking the Save button their gender is set to Unspecified.

What is causing their gender to be set to Unspecified, and how would I stop that?

Thanks.
 
If the form is submitted and no "gender" value is there, it defaults to "unspecified" even if it was specified before.

You have to add
Code:
<input type="hidden" name="gender" value="{$visitor.gender}">
in an <xen: else> condition.
 
Terrific, thank-you!

For anyone else interested in doing the same, this is my final template change ...

Code:
<xen:if is="!{$visitor.gender}">
        <dl class="ctrlUnit">
            <dt><label>{xen:phrase gender}:</label></dt>
            <dd>
                <ul>
                    <li><label for="ctrl_gender_male"><input type="radio" name="gender" value="male" id="ctrl_gender_male" {xen:checked "{$visitor.gender} == 'male' OR !{$visitor.gender}"} /> {xen:phrase male}</label></li>
                    <li><label for="ctrl_gender_female"><input type="radio" name="gender" value="female" id="ctrl_gender_female" {xen:checked "{$visitor.gender} == 'female'"} /> {xen:phrase female}</label></li>
<xen:comment>
                    <li><label for="ctrl_gender_"><input type="radio" name="gender" value="" id="ctrl_gender_" /> ({xen:phrase unspecified})</label></li>
</xen:comment>
                </ul>
            </dd>
        </dl>
<xen:else />
    <input type="hidden" name="gender" value="{$visitor.gender}">
</xen:if>
 
Back
Top Bottom