Limit the Number of Characters in Discuz! X3.4 Post Titles

8,039 3

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):

JavaScript
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:

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

Comments

(3)
  1. Chrome 78 Windows 10

    我认为在DZ Q 没推出之前再转入DZ是一个不好的选择,Flarum已经就完善的生态了,一个创始人的离开并不来代表项目死了,因为一个开源社区的力量远远大于一个人的力量

    1. Chrome 80 Windows 10

      您的观点是完全正确的,事实证明 toby离开之后,flarum发展迅速,下周即将发布bate12版本,很值得期待。 而我所运营的一个社区 www.yoknet.cn 也最终抛弃discuz转而拥抱flarum,社区开源的力量确实强大,我几乎能在社区里找到任何我想要的功能。 至于discuz Q,我个人认为连discuz X都取代不了

    2. Chrome 78 Windows 10

      确实,我认为Flarum非常棒,所以我也正在积极筹备一个unity的中文学习社区! ::twemoji:smile:: www.nwdgame.com

Leave a comment

© 2026 Carefree. All rights reserved.

Carefree is a personal site about technology and everyday life, documenting web development, backend, and DevOps practices, plus software tools, digital experiences, and thoughts beyond code.