Some time ago, I changed the “iApp Community” to the “Youwan Community” and also switched the software from Flarum to Discuz. Why did I switch? Because Flarum’s author, Toby, seems to have left Flarum’s development. From now on, Flarum will be maintained by the community, and the latest version is still Beta 9.
Five years have passed since Beta 1 was released in 2014, yet we still haven’t gotten a stable release. Now that Toby has left again (Farewell and What's Next For Flarum), it remains unknown how far Flarum can go in the future. If this is the reason I chose to switch to Discuz, it seems somewhat far-fetched.
Compared with Flarum, Discuz actually died even earlier. Ever since it was acquired by Tencent, there hasn’t been much activity.
Even so, as a forum platform, Discuz is relatively mature in China. After more than ten years of development, Discuz has most of the features a forum should have, and it also offers enough plugins and templates with strong extensibility. That is the real reason I chose Discuz.
After saying all that, I simply wanted to document how to limit the number of characters in post titles in Discuz. I also wrote an article about this issue when I was using Flarum.
{cat_insidepost id="115"}
Now let’s take a look at how to modify it in Discuz.
File path /static/js/forum_post.js
Find the following code (in Discuz 3.4, it should be around line 75):
if(($('postsubmit').name != 'replysubmit' && !($('postsubmit').name == 'editsubmit' && !isfirstpost) && theform.subject.value == "") || !sortid && !special && trim(message) == "") {
showError('抱歉,您尚未输入标题或内容');
return false;
} else if(mb_strlen(theform.subject.value) > 80) {
showError('您的标题超过 80 个字符的限制');
return false;
}
Add the following below it:
else if(mb_strlen(theform.subject.value) < 20 && mb_strlen(theform.subject.value) > 0) {
showError('您的标题不足 20 个字符的限制');
return false;
}
Note that one Chinese character takes up two character counts. That’s all there is to it.