Making Display Name On Registration a required field

Started by LennyH, March 06, 2017, 03:47:30 PM

Previous topic - Next topic

LennyH

So I've been using this mod http://custom.simplemachines.org/mods/index.php?mod=1747 and I noticed that the Display Name field can be left empty as the member registers but I wanted it to be a required field so they can't complete registration without filling it. I've tried several methods to make it a required field but I kept hitting a brick wall. I really need help with this.
Thanks in Advance.

EDIT: I'm using SMF 2.0.13 but emulated 2.0 RC2 in order to install the mod and it installed just fine without giving an error.

Sir Osis of Liver

Haven't installed the mod, but look in smf_custom_fields in your database and see if there's a row for real_name.  If it's there, change show_reg to '2'.  If it works, see which error it throws.
Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

LennyH

Quote from: Sir Osis of Liver on March 06, 2017, 10:08:16 PM
Haven't installed the mod, but look in smf_custom_fields in your database and see if there's a row for real_name.  If it's there, change show_reg to '2'.  If it works, see which error it throws.
I went to smf_custom_fields and didn't find any rows for real_name, even searched smf_custom_fields and didn't find any but there was a show_reg and after changing it to 2 I didn't notice any changes or any errors.

LennyH

And I don't want to use Advanced Profile Fields in Core Features because that won't replace Display name or 'real_name'. I want users to have different display name and username when they register.

Sir Osis of Liver

Yeah, didn't think that would work.  real_name is in smf_members, that's the value the mod is adding.  Do you want members to still have option to change display name in Profile?
Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Sir Osis of Liver

The mod doesn't work in 2.0.13, whether installed with package manager (RC2 emulation) or manually.  Whatever is entered in Display Name field causes 'The "Display name" field cannot be left blank.' error, and field returns blank.  Did you get it to work?
Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

LennyH

Well, I tested it on my localhost with emulation, it gets installed and if you fill the Display name field at registration it will work but there is no way to force it to be a required field and if a user skips it, the username will be auto set as display name. I'm new to php and smf but I tried to see how smf makes the username field a required field and I tried to make the mod to do the same but I was even unable to locate the code for it, also searched the database for a clue but nothing.

Illori

that is because you cant register without some required fields, the rest are not required. what you want to do is more complicated then just copying what is already there. since this is not a custom profile field you cant use that code and you may not be able to use some of the other required code due to how it is coded. you really need to dig in and know php to figure out this one.

Sir Osis of Liver

Don't know why it doesn't work on my test install, but the mod really is no help.  Will tinker with the code when I have some time tonight.  As Illori points out, it's complicated, in addition to adding a required field that updates smf_members, it also has to run the check to see if the name has already been used.
Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Arantor

Which most of the code in registerMember already does. You just need to add an additional check so it has an extra place to return if you didn't provide a display name.

Sir Osis of Liver

Ok, I can make display name a required field (thanks Arantor), but doing the check to see if the display name has already been used is a whole nother thing.  If the check is not done, and the display name is used, registration will succeed, but display name will revert to username when registration is completed.  Some of the check is in Register.php, and some is in register.js

Sir Osis hates javascript.


Here's how to make the field required.  First, install the display name mod using RC2 emulation (you've already done that).  Then, make these edits -

/Sources/Subs-Members.php



/// No name?!  How can you register with no name?
if (empty($regOptions['username']))
$reg_errors[] = array('lang', 'need_username');

if (empty($regOptions['real_name']))
$reg_errors[] = array('lang', 'need_displayname');

// Spaces and other odd characters are evil...




/Themes/default/languages/Login.english.php



/// Registration form.
$txt['registration_form'] = 'Registration Form';
$txt['need_username'] = 'You need to fill in a username.';

$txt['need_displayname'] = 'You need to fill in a display name.';

$txt['no_password'] = 'You didn\'t enter your password.';




Will have a go at the js stuff after a few more beers, but don't hold your breath.
Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Advertisement: