Uutiset:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu
Advertisement:

Set a username/display name character limit

Aloittaja Aaron10, helmikuu 19, 2011, 01:36:48 IP

« edellinen - seuraava »

Aaron10

Wondering if its possible to limit usernames to say 12 characters long? Thanks.

Aaron10


Joker™

Github Profile
Android apps
Medium

How to enable Post Moderation

"For the wise man looks into space and he knows there is no limited dimensions." - Laozi

All support seeking PM's get microwaved

Aaron10


Joker™

make backup of files before editing them

go to

Themes\Default\Register.template.php

Find:
<input type="text" name="user" size="20" tabindex="', $context['tabindex']++, '" maxlength="25" />


Replace it with:
<input type="text" name="user" size="10" tabindex="', $context['tabindex']++, '" maxlength="12" />


Find:
<input type="text" name="user" id="user_input" size="20" maxlength="12" />


Replace it with:
<input type="text" name="user" id="user_input" size="20" maxlength="12" />
Github Profile
Android apps
Medium

How to enable Post Moderation

"For the wise man looks into space and he knows there is no limited dimensions." - Laozi

All support seeking PM's get microwaved

Aaron10


Chris180

Lainaus käyttäjältä: Joker™ - helmikuu 21, 2011, 09:01:54 AP
make backup of files before editing them

go to

Themes\Default\Register.template.php

Find:
<input type="text" name="user" size="20" tabindex="', $context['tabindex']++, '" maxlength="25" />


Replace it with:
<input type="text" name="user" size="10" tabindex="', $context['tabindex']++, '" maxlength="12" />


Find:
<input type="text" name="user" id="user_input" size="20" maxlength="12" />


Replace it with:
<input type="text" name="user" id="user_input" size="20" maxlength="12" />


Out of curiosity, why did you change the text size from 20 to 10?

Anyway, thanks very much :).

Arantor

Because the size parameter doesn't affect content size but the size of the box shown to users. If it looks smaller they will be less inclined to write long names anyway.

Not that maxlength is even remotely guaranteeing anything; almost all modern browsers come with tools to edit the webpage, remove that limit and it'll be accepted. Needs to be enforced on the server, not the client.
Holder of controversial views, all of which my own.


Ninja ZX-10RR

I'll bump this old topic up by asking how to do this in 2.0.7 because the file is obviously different but i have no idea of where to find such fields. Also i would like to set the limit for the name that is being shown (you can change it as an admin if you want but leaving the username unchanged).
Lainaus käyttäjältä: BeastMode topic=525177.msg3720020#msg3720020
It's so powerful that on this post and even in the two PMs you sent me,you still answered my question very quickly and you're apologizing for the delay. You're the #1 support I've probably ever encountered man, so much respect for that. Thank you, and get better soon.

I'll keep this in my siggy for a while just to remind me that someone appreciated what I did while others didn't.

♥ Jess ♥

STOP EDITING MY PROFILE

Arantor

Except the code is, as mentioned, not especially useful since a user can trivially bypass it.
Holder of controversial views, all of which my own.


Ninja ZX-10RR

D: How could a user bypass it? Why? And, most importantly, how to fix it and anyway how to edit it?
Lainaus käyttäjältä: BeastMode topic=525177.msg3720020#msg3720020
It's so powerful that on this post and even in the two PMs you sent me,you still answered my question very quickly and you're apologizing for the delay. You're the #1 support I've probably ever encountered man, so much respect for that. Thank you, and get better soon.

I'll keep this in my siggy for a while just to remind me that someone appreciated what I did while others didn't.

♥ Jess ♥

STOP EDITING MY PROFILE

Arantor

Easy: press F12, inspect the element, remove the maxlength parameter. Chrome and Opera can do this and have been able to for ages. I think FF still needs Firebug to do this. Not sure about IE's dev tools lately, haven't used it.

Fixing it? Completely new code elsewhere in the bowels of SMF, not just changing the registration form.
Holder of controversial views, all of which my own.


Ninja ZX-10RR

Thanks as always for the reply, quick as a lightning.

Well i don't think 99% of users would really be able to bypass it, i wouldn't think of it for instance even if i know what you are talking about.
I was hoping there was some sort of restriction somewhere in smf files! What the heck i think it is stupid leaving such an important feature like this buggy and not working perfectly. There must and i mean MUST be a code telling smf to accept names that are shorter than a given X value. If there is not such a string then it's vital to understand where the string is so at least FOR RIGHT NOW we can fix it and set a character limit, then for "smart" users using inspect element there will be a renaming action. But meantime where the heck did that string go? There is a limit of 25 right? So there must be a damn line telling smf "hei you must accept only usernames under 25 chars otherwise don't". Any clues?

*damn i feel always embarrassed and honoured just because you replied  :-[ my forum owes you so much, i will not forget it trust me*
Lainaus käyttäjältä: BeastMode topic=525177.msg3720020#msg3720020
It's so powerful that on this post and even in the two PMs you sent me,you still answered my question very quickly and you're apologizing for the delay. You're the #1 support I've probably ever encountered man, so much respect for that. Thank you, and get better soon.

I'll keep this in my siggy for a while just to remind me that someone appreciated what I did while others didn't.

♥ Jess ♥

STOP EDITING MY PROFILE

Arantor

It is working perfectly as designed. The fact you want a different design doesn't make it buggy. It merely makes it different.

You actually have to modify it in two places to make this work properly. First in Register.php:
if ($smcFunc['strlen']($context['checked_username']) > 25)
$context['checked_username'] = $smcFunc['htmltrim']($smcFunc['substr']($context['checked_username'], 0, 25));


Secondly in Subs-Members.php:
// Don't use too long a name.
if ($smcFunc['strlen']($regOptions['username']) > 25)
$reg_errors[] = array('lang', 'error_long_name');
Holder of controversial views, all of which my own.


Ninja ZX-10RR

#14
I don't actually want it different i just want it to be not-bypassable xD

Thanks anyway, as always flawless where you can.

MERGED POST
As you very quick i'll post again so i'm sure you will see. I'll merge posts when you reply.

Does this work for nicknames as well? I mean nicknames being different from usernames? I think you understood but i try to explain myself better anyway... As an admin i have the possibility to edit the name i can show and leaving the username with which i login untouched. I would like the shown names to use the same criteria. I mean not more than X value, should i have to edit something else or is it fine like this? And why? If you bother explaining me the reason as well xD

Thanks again, as always.
Lainaus käyttäjältä: BeastMode topic=525177.msg3720020#msg3720020
It's so powerful that on this post and even in the two PMs you sent me,you still answered my question very quickly and you're apologizing for the delay. You're the #1 support I've probably ever encountered man, so much respect for that. Thank you, and get better soon.

I'll keep this in my siggy for a while just to remind me that someone appreciated what I did while others didn't.

♥ Jess ♥

STOP EDITING MY PROFILE

Arantor

Display names are validated to be shorter than 60 characters. Changing *that* is even more complicated :P But it is possible to do.
Holder of controversial views, all of which my own.


Ninja ZX-10RR

Crap xD i guess i'm gonna have to bother you again... Would you mind taking a look at it if you want and if you have time? I have no idea of where that could be as as far as i can see it's not close to the codes i have just edited following your instructions...

Thanks again, i guess i will have to create a canned thanks reply when you reply lol coz you always fix me something when you do.
Lainaus käyttäjältä: BeastMode topic=525177.msg3720020#msg3720020
It's so powerful that on this post and even in the two PMs you sent me,you still answered my question very quickly and you're apologizing for the delay. You're the #1 support I've probably ever encountered man, so much respect for that. Thank you, and get better soon.

I'll keep this in my siggy for a while just to remind me that someone appreciated what I did while others didn't.

♥ Jess ♥

STOP EDITING MY PROFILE

Arantor

It's primarily set by Profile-Modify.php:
'input_attr' => array('maxlength="60"'),
elseif ($smcFunc[\'strlen\']($value) > 60)
return \'name_too_long\';
Holder of controversial views, all of which my own.


Ninja ZX-10RR

O.o only? It's even easier than the other one... Well thanks a lot, (again, *coughs*) NOW the topic is really SOLVED also for this SMF version. :D
Lainaus käyttäjältä: BeastMode topic=525177.msg3720020#msg3720020
It's so powerful that on this post and even in the two PMs you sent me,you still answered my question very quickly and you're apologizing for the delay. You're the #1 support I've probably ever encountered man, so much respect for that. Thank you, and get better soon.

I'll keep this in my siggy for a while just to remind me that someone appreciated what I did while others didn't.

♥ Jess ♥

STOP EDITING MY PROFILE

Arantor

For you, yes. For me, not so much since I had to figure out WTF it was set :P

Intercepting registration is easy, there are only two places it *can* be. But the code for the real name field, not so much. Technically there's an edge case I haven't covered but it's such an edge case that it doesn't matter (one can set their display name on registration even if the field isn't shown to users, along with a bunch of other stuff)
Holder of controversial views, all of which my own.


Advertisement: