News:

Wondering if this will always be free?  See why free is better.

Main Menu

Gender required at Registration

Started by Matthias, March 05, 2019, 11:32:12 AM

Previous topic - Next topic

Matthias

I already searched the forum, but did not find the solution. I'm using 2.0.15

In Register.template.php i added the following:
Search for:
<div class="windowbg2">
<span class="topslice"><span></span></span>
<fieldset class="content">
<dl class="register_form">
<dt><strong><label for="smf_autov_username">', $txt['username'], ':</label></strong></dt>
<dd>
<input type="text" name="user" id="smf_autov_username" size="30" tabindex="', $context['tabindex']++, '" maxlength="25" value="', isset($context['username']) ? $context['username'] : '', '" class="input_text" />
<span id="smf_autov_username_div" style="display: none;">
<a id="smf_autov_username_link" href="#">
<img id="smf_autov_username_img" src="', $settings['images_url'], '/icons/field_check.gif" alt="*" />
</a>
</span>
</dd>
<dt><strong><label for="smf_autov_reserve1">', $txt['email'], ':</label></strong></dt>
<dd>
<input type="text" name="email" id="smf_autov_reserve1" size="30" tabindex="', $context['tabindex']++, '" value="', isset($context['email']) ? $context['email'] : '', '" class="input_text" />
</dd>
<dt><strong><label for="allow_email">', $txt['allow_user_email'], ':</label></strong></dt>
<dd>
<input type="checkbox" name="allow_email" id="allow_email" tabindex="', $context['tabindex']++, '" class="input_check" />
</dd>


After that I have added:
<dd>
<select name="gender" id="smf_autov_reserve1" tabindex="', $context['tabindex']++, '">
<option value="0" selected="selected">', $txt['undefined_gender'], '</option>
<option value="1" >', $txt['male'], '</option>
<option value="2" >', $txt['female'], '</option>
</select>
</dd>


The Gender field is also displayed at registration. But it's possible to register without selecting male or female.

In Register.php in the sources directory i have added the following:
Search for:
// Set the options needed for registration.
$regOptions = array(
'interface' => 'guest',
'username' => !empty($_POST['user']) ? $_POST['user'] : '',
'email' => !empty($_POST['email']) ? $_POST['email'] : '',
'password' => !empty($_POST['passwrd1']) ? $_POST['passwrd1'] : '',
'password_check' => !empty($_POST['passwrd2']) ? $_POST['passwrd2'] : '',
'openid' => !empty($_POST['openid_identifier']) ? $_POST['openid_identifier'] : '',
'auth_method' => !empty($_POST['authenticate']) ? $_POST['authenticate'] : '',
'check_reserved_name' => true,
'check_password_strength' => true,
'check_email_ban' => true,
'send_welcome_email' => !empty($modSettings['send_welcomeEmail']),
'require' => !empty($modSettings['coppaAge']) && !$verifiedOpenID && empty($_SESSION['skip_coppa']) ? 'coppa' : (empty($modSettings['registration_method']) ? 'nothing' : ($modSettings['registration_method'] == 1 ? 'activation' : 'approval')),
'extra_register_vars' => array(),
'theme_vars' => array(),


After that I have added:
'gender' => array('name' => ($_POST['gender'] == 2 ? 'f' : 'm'),

When I call register the page, I get a blank page.

Can someone help me please.
Quality first

Looking

I think you can do this same thing with custom fields - no need to edit code.

vbgamer45

Can you attach your register.php and register.template.php I just want to see if any php errors.
Community Suite for SMF - Grow your forum with SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com - Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Matthias

Quality first

vbgamer45

Community Suite for SMF - Grow your forum with SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com - Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Matthias

Thanks for the quick help. The registration page can be called now. But the registration is still possible without specifying the gender.
What else needs to be adjusted so that the registration works only with the indication of the gender.
Quality first

vbgamer45

I would add a check in register.php before


// Lets check for other errors before trying to register the member.
if (!empty($reg_errors))
{
$_REQUEST['step'] = 2;
return Register($reg_errors);
}
Community Suite for SMF - Grow your forum with SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com - Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Sir Osis of Liver

Quote from: Looking on March 05, 2019, 11:36:45 AM
I think you can do this same thing with custom fields - no need to edit code.

This has been addressed several times, just create a required custom field, remove default gender field.
When in Emor, do as the Snamors.
                              - D. Lister

Advertisement: