News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Minimum character limit for subjects

Started by Mirez, October 27, 2016, 09:16:01 AM

Previous topic - Next topic

Mirez

Hi All!

I'm trying to find a way to make my users use more descriptive subjects; not only to aid other users find the post but also because good information is being 'lost' in threads with poor subjects and less useful info is being ranked higher because it has a better subject.

Certainly not wanting anything too draconian, just to be able to set a mimimum number of characters for the subject field.

Arantor

Requires a number of changes, not least physically making the database space available for subject bigger.

Mirez

Hi Arantor,

I may not have been clear enough there, I dont want to increase the number of characters available in the subject but rather set a minimum number.

For example, if I could set a minimum limit of 10 characters it would stop topics with subjects such as "Help" or "Problem" and force them to use something more descriptive...

Shambles

Here's what you could do.

Open Sources/Post.php and find the following block of code:

Code (Find) Select

// Check the subject and message.
if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '')
$post_errors[] = 'no_subject';
if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '')
$post_errors[] = 'no_message';


Add a couple of lines as follows:

Code (Replace) Select

// Check the subject and message.
if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '')
$post_errors[] = 'no_subject';
if (isset($_POST['subject']) && strlen($_POST['subject']) < 10)
$post_errors[] = 'short_subject';
if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '')
$post_errors[] = 'no_message';


Then, open your Themes/default/languages/Errors.english.php and add the following, just before the closing ?>

Code (Add) Select

$txt['error_short_subject'] = 'The subject is too short.';


The "10" I used in the first edit is the minimum character count.

Arantor

Oops, I read it as maximum, not minimum.

I also thought there were mods already for that, fairly sure I wrote one at some point. But what Shambles has posted should do just fine :)

Kindred

There was a minimum post-length mod...   don't recall ever seeing a minimum subject length.
(and, I think this will backfire...   you'll get the same subjects,just added chars...
like
"Help me!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
instead of just "Help me"
and then again,
"This was awesome"
would fit your minimum, but is still useless as an SEO subject

trying to enforce SEO on a forum with user posts is basically useless.
Слaва
Украинi

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."

Mirez

Perfect thanks everyone! I did look for a mod but couldnt find one so I will modify the code as above.

I know its unlikely to improve things too much but then just weeding out a few is a start!

Thanks again.

Advertisement: