Increase Subject Length

By default, phpBB 2 limits the length of post and topic subjects to 60 characters. In some boards, it is desirable to allow longer subjects, so this is a guide to hacking your phpBB to increase the limit. We will use 120 as the new subject length here, but you can use a different number by simply changing 120 to that number in the instructions that follow.

Before beginning, let me point out some limitations of this guide and the methods we will be using. The maximum subject length allowed by the MySQL database software is 255 characters, and this cannot be exceeded by the methods we will be using (there is a way, which we'll look at later). Other database management software (DBMS) may have different character limits. We will also be using SQL queries to alter the database tables. These queries are written for use in MySQL. If you are using another DBMS, you may need to edit the queries before you can use them. Now, on to the hacking!

There are two steps to increasing the subject length. First, you need to run a couple of SQL queries. You can do this using a database utility like phpMyAdmin or a Database Update script. If you use phpMyAdmin, you may need to change the phpbb_ prefix of the database table names in these queries. Database Update scripts will handle that automatically.

ALTER TABLE phpbb_posts_text CHANGE post_subject post_subject VARCHAR(120) DEFAULT NULL;
ALTER TABLE phpbb_topics CHANGE topic_title topic_title VARCHAR(120) NOT NULL;

The second step is to edit the posting_body.tpl file of each template installed on your forum. You need to find a certain line in this file, but as you may know, different templates tend to use very different coding. Below, you can see what the line looks like in subSilver. If you cannot find this exact line in your file, try looking for a line containing name="subject" or name='subject'.

<input type="text" name="subject" size="45" maxlength="60" style="width:450px" tabindex="2" class="post" value="{SUBJECT}" />

Now, check that line to see if it contains the text maxlength, followed by a number (in this case, the line contains maxlength="60"). If you find the line does not contain maxlength, you can skip this step. No edits are required here when there is no maxlength set.

Assuming that the maxlength attribute is there, change the number following it (60 in this example) to 120. Here is the subSilver line with this change.

<input type="text" name="subject" size="45" maxlength="120" style="width:450px" tabindex="2" class="post" value="{SUBJECT}" />

Now your posters can enter subject lines of greater length when making, editing, or replying to posts and private messages.

Allowing More Than 255 Characters

I mentioned before that there is a 255 character limit when changing the allowed subject length with the method described above. There is one way to exceed this length, but you must be careful when using it. This alternate method allows subjects that can potentially be much longer, even as long as a full post.

To use this method, you need to run a different set of SQL queries. A third query is included here for private message subjects, which did not need to be changed with the other method. If you want to keep those at their default limit of 255 characters, skip that query. MySQL users can replace TEXT with TINYTEXT in these queries for shorter (but still very long) subject allowances.

ALTER TABLE phpbb_posts_text CHANGE post_subject post_subject TEXT DEFAULT NULL;
ALTER TABLE phpbb_topics CHANGE topic_title topic_title TEXT NOT NULL;
ALTER TABLE phpbb_privmsgs CHANGE privmsgs_subject privmsgs_subject TEXT NOT NULL;

The second step is essentially identical to that of the first method. You need to find and change the maxlength attribute to a larger number as described there. The number you use will be the maximum limit of subjects allowed from the posting form. You can use whatever number you wish. If there is not a maxlength attribute, I strongly suggest adding one, as there will be little other limitations on the subject length. The DBMS will have its own set limit, but that is a very high limit.