ElkArte Community

Project Support => Support => Topic started by: Ruth on June 09, 2016, 05:49:48 am

Title: Shorten user names
Post by: Ruth on June 09, 2016, 05:49:48 am
Hello!

Is there a possibility, to keep the usernames short, when people are using the registerform?
They should not be able to type more than a maximum of 14 characters for their usernames.

Title: Re: Shorten user names
Post by: emanuele on June 09, 2016, 06:42:34 am
All the username validation is done in Auth.subs.php function validateUsername.
The first check is length that is set to 25, if you want to force them down to 14 you can change the 25 to 15.
I'm not sure at the moment it can be done without modifying the code, but looking at that function is a nice spot for some changes. O:-)
Title: Re: Shorten user names
Post by: Ruth on June 09, 2016, 06:57:17 am
Thank you very much, Emanuele.

I have tried this, but it is still possible to type 25 characters into the field.
Title: Re: Shorten user names
Post by: Frenzie on June 09, 2016, 08:10:21 am
You'd have to add maxlength=14 to the relevant INPUT in the theme file. See http://www.w3schools.com/tags/att_input_maxlength.asp
Title: Re: Shorten user names
Post by: emanuele on June 09, 2016, 11:06:14 am
Quote from: Ruth – I have tried this, but it is still possible to type 25 characters into the field.
But they should get a "registration error".
Title: Re: Shorten user names
Post by: Ruth on June 09, 2016, 12:27:04 pm
Yes, they will get an error message. It is working fine that way. (I did not try to finish the registration first.) O:-)

I have changed this string $txt['error_long_name'] in Errors.german.php a little, to tell them, that their usename may not have more than 14 characters.

But it would be better to tell them about this, before they will get an error, in the registerform itself.  Can I add something there to "Username"?

This string in index.german.php $txt['username'] = 'Benutzername'; is not only used while you register, it is also used for the login, as I believe?
Title: Re: Shorten user names
Post by: Ruth on June 09, 2016, 01:42:34 pm
Can I add a little text here in Register.template.php for explaining?

Code: [Select]
	echo '
<form action="', $scripturl, '?action=register2" method="post" accept-charset="UTF-8" name="registration" id="registration" onsubmit="return verifyAgree();">
<h2 class="category_header">', $txt['registration_form'], '</h2>
<h3 class="category_header">', $txt['required_info'], '</h3>
<div class="windowbg2">
<input type="password" name="autofill_honey_pot" style="display:none" />
<fieldset class="content">
<dl class="register_form">
<dt>
<strong><label for="elk_autov_username">', $txt['username'], ':</label></strong>
</dt>
<dd>
<input type="text" name="user" id="elk_autov_username" size="30" tabindex="', $context['tabindex']++, '" maxlength="25" value="', isset($context['username']) ? $context['username'] : '', '" class="input_text" placeholder="', $txt['username'], '" required="required" autofocus="autofocus" />
<span id="elk_autov_username_div" style="display: none;">
<a id="elk_autov_username_link" href="#">
<img id="elk_autov_username_img" src="', $settings['images_url'], '/icons/field_check.png" alt="*" />
</a>
</span>
</dd>

A break after this?
Code: [Select]
<strong><label for="elk_autov_username">', $txt['username'], ':</label></strong>

Title: Re: Shorten user names
Post by: emanuele on June 09, 2016, 01:48:06 pm
Quote from: Ruth – This string in index.german.php $txt['username'] = 'Benutzername'; is not only used while you register, it is also used for the login, as I believe?
I guess so, honestly I don't remember, but considering how general it is, it's likely used in many places. :)

Quote from: Ruth – Can I add a little text here in Register.template.php for explaining?
Why do you ask me if you can? :P
Of course you can.
Title: Re: Shorten user names
Post by: Ruth on June 09, 2016, 01:55:37 pm
Because I am a big coward and don't want to do any mistake in the files.

I was not sure about it, therefore  I asked.
Title: Re: Shorten user names
Post by: Frenzie on June 09, 2016, 03:51:12 pm
Code: [Select]
<input type="text" name="user" id="elk_autov_username" size="30" tabindex="', $context['tabindex']++, '" maxlength="25" value="', isset($context['username']) ? $context['username'] : '', '" class="input_text" placeholder="', $txt['username'], '" required="required" autofocus="autofocus" />
In that line, just change maxlength=25 to maxlength=14.
Title: Re: Shorten user names
Post by: Ruth on June 09, 2016, 11:29:48 pm
Thank you very much, Frenzie. I changed it in this line now.