Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

How to increase topic tilte/subject length?

Started by waplist, April 04, 2017, 01:27:26 AM

Previous topic - Next topic


         I tried to create new topic but i think smf doesnt allow title longer titles . there is also no setting to change that in smf.  Help on this thank you



Sorry actually its 2.0.13.


And, the next question is..  why?

Why do you think you need a topic longer than 80 characters?

In almost every case, when someone asks for this, they are attempting to "abuse" the system for a reason that is not actually necessary or even good.

And, as to why it's not a setting... you would gave to change a source file, a template file and the database

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."


sorry to bump an old topic, and hijack it
but I have the same question....
I need to lengthen the topic title
I post a lot of article type posts and have run into the issue of the title character limit, can't find a setting in the admin to change it
I would think that 120 would be more than enough


Shouldn't need a database change. It's already varchar(255) which is more than adequate.

The template code is here, in Post.template.php:

// Now show the subject box for this post.
echo '
<span', isset($context['post_error']['no_subject']) ? ' class="error"' : '', ' id="caption_subject">', $txt['subject'], ':</span>
<input type="text" name="subject"', $context['subject'] == '' ? '' : ' value="' . $context['subject'] . '"', ' tabindex="', $context['tabindex']++, '" size="80" maxlength="80" class="input_text" />

Where the size is just the visible width, and the max length is the critical part. The database would allow you to set 255 here if you were that bonkers.

The trickier part is Sources/Post.php (because Sources is always a tad gnarly IME):

// Make sure the subject isn't too long - taking into account special characters.
if ($smcFunc['strlen']($form_subject) > 100)
$form_subject = $smcFunc['substr']($form_subject, 0, 100);

Which is obviously happy with 100 characters, but will truncate anything over that. It should, I think, be safe to increase that to 120 if you need that many. At which point Arantor will probably pop up and tell me about all sorts of dire things that will happen.


As requested.

255 is only enough if you don't have special characters in the subject. The relationship between the logical length of the string and the physical is tenuous at best.

A " will consume 6 out of the 255 but only 1 out of the 100/120. Emojis are the worst though, they usually only count as 1 out of the 100/120 but up to 9 out of the 255, each.

That's why the disjoint, trying to cover as many cases of space consumption as possible, or at least, as was likely at the time (as those numbers were set long before the current emoji even existed)

The only problem is that it will truncate somewhat spuriously in this case, either with an error or more likely no error and then you just get a mangled title. Or it gets mangled later by the forced "Re:" stuff that is normally covered but suddenly now might not be.


Learn something every day. Ok, do you think it would be safe to increase it to 100, to match the truncation limit in Post.php?

Assuming that whoever was using it had enough sense to not fill the subject up with smileys and special ZOMG characters.

Which some clown is bound to do sooner or later, but you can always just point at them and start giggling.


Even 120 is safe as long as the subject isn't full of ', ", <, >, & or emojis. These are all characters that are stored in an encoded format. A few is ok, a lot breaks it.


Caveat scriptor, then. :)

I suppose it would technically be possible to break things even with the default 80 character limit, if you specifically set out to do that just to prove a point.


Yup, and it has been observed, but generally it isn't usually a problem, because most posts don't trip over this, because topic titles that are a mass of specific punctuation are annoying as are topics that are just emoji.


thank you both and interesting info
hopefully smilies and whatnots won't be an issue

so then am I correct in that I changed, the 80's to 120's
<input type="text" name="subject"', $context['subject'] == '' ? '' : ' value="' . $context['subject'] . '"', ' tabindex="', $context['tabindex']++, '" size="120" maxlength="120" class="input_text" />

and that I changed the 100's to 120's

// Make sure the subject isn't too long - taking into account special characters.
if ($smcFunc['strlen']($form_subject) > 120)
$form_subject = $smcFunc['substr']($form_subject, 0, 120);

it seems to work so far....