View Full Version : Thread title only alphanumeric and space
Gripi
08-26-2011, 06:15 PM
hi...
could someone help me to make the thread title in every new thread can only use "alphanumeric and space" ?
i dont want any special character in the thread title.
thanks alot
Create a new plugin using hook location newpost_process and this code:
if (!preg_match('/^[A-Za-z0-9\s]+$/', $post['title']))
$errors[] = "Only letters, number, and spaces are allowed in title.";
Gripi
08-27-2011, 03:45 AM
thank you very2 much :)
Badshah93
08-27-2011, 04:20 AM
Create a new plugin using hook location newpost_process and this code:
if (!preg_match('/^[A-Za-z0-9\s]+$/', $post['title']))
$errors[] = "Only letters, number, and spaces are allowed in title.";
I think plugin hook should be changed to newthread_post_start
OR
code should be modified to
iif (!preg_match('/^[A-Za-z0-9\s]+$/', $post['title']) AND $type == 'thread')
$errors[] = "Only letters, number, and spaces are allowed in title.";
Because the present code will check for new reply also. and generally new reply title are like this
Re: //title
Because the present code will check for new reply also. and generally new reply title are like this
Good point. But changing the hook to newthread_post_start doesn't seem to work. Your second suggestion works except that you have 'iff' at the beginning (is that a typo?).
Checking for $type == 'thread' will allow any characters in reply titles, but the OP does specifically say "thread titles", so maybe that's OK.
Gripi, sorry for any problems this may have caused on your forum. :o
Edit: I also figured out that it only quotes the title with "Re:" if you have set the "Automatically Quote Post / Thread Title" to true, otherwise title is blank by default (which also caused a problem since the pattern didn't allow blank titles). So I have the following suggestion (using newpost_process):
if ($type != 'thread' && $vbulletin->options['quotetitle'])
$titlepat = '/^(' . preg_quote($vbphrase['reply_prefix'], "/") . ')?[A-Za-z0-9\s]*$/';
else
$titlepat = '/^[A-Za-z0-9\s]*$/';
if (!preg_match($titlepat, $post['title']))
$errors[] = "Only letters, number, and spaces are allowed in title.";
Badshah93
08-27-2011, 05:53 AM
Good point. But changing the hook to newthread_post_start doesn't seem to work. Your second suggestion works except that you have 'iff' at the beginning (is that a typo?).
Checking for $type == 'thread' will allow any characters in reply titles, but the OP does specifically say "thread titles", so maybe that's OK.
Gripi, sorry for any problems this may have caused on your forum. :o
YA ITS IF NOT IIF
if (!preg_match('/^[A-Za-z0-9\s]+$/', $post['title']) AND $type == 'thread')
$errors[] = "Only letters, number, and spaces are allowed in title.";
For newthread_post_start hook we need to modify the code to this
if (!preg_match('/^[A-Za-z0-9\s]+$/', $vbulletin->GPC[subject]))
standard_error("Only letters, number, and spaces are allowed in title.");
Gripi
08-28-2011, 04:56 PM
once again thanks, i'm thinking to put the code in the beta forum this monday, i will let you know if the code works or not.
Gripi
10-22-2011, 08:12 AM
Hi again...
could you please tell me how to automaticly remove any character beside alphanumeric and space in the title when someone post a new thread or a new post?
i dont want any warning error msg, just submit the post / thread to database, and remove any ilegal character.
thanks
--------------- Added 1319275153 at 1319275153 ---------------
and is it possible to make the plugin to work like this:
not just allowing alphanumeric and space, but remove character that i choose.
If you want to replace any non-alphanumeric or space chars you can use preg_replace() like:
$pattern = '/[^a-zA-Z0-9 ]/';
$replace = ' ';
$post['title'] = preg_replace($pattern, $replace, $post['title']);
$replace is a space in that example, you can make it a null string if you want to delete the char instead.
If you want to only eliminate one or a set of chars you could change $pattern to a list of the chars to delete, like:
$pattern = '/[@#*$]/';
...
Gripi
10-23-2011, 06:12 PM
thank you
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.