MyBB Community Forums

Full Version: Datahahandler Issue
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Im playing about with the datahandler hooks to trigger post/thread errors and have an issue when using:

$plugins->add_hook("datahandler_post_validate_thread", "test_run");

When I use the hook above and the function below to trigger errors while creating a "new thread", the error displays but if the condition is true, the error still displays and prevents the thread from being created. Any ideas why ?

function test_run()
{
	global $db,$mybb,$forum,$fid,$posthandler,$post,$thread;
				
	if ($forum['fid'] == 1)
	  	{
			$mess = $post['message'];
			
			if(strlen($mess) < 50)
			{
                $posthandler->set_error("Error Message Here.....");
                return false;
            }
	  }
 	}
Your hook second parameter and the function name are not same.
Thats a typo in the post sorry, thats not the issue.
OK, Try this;
function test_run()
{
    global $db,$mybb,$forum,$fid,$posthandler,$post,$thread;
                
    if ($forum['fid'] == 1)
          {
            $mess = $post['message'];
            
            if(strlen($mess) < 50)
            {
                  $post->is_validated = false;
		  $post->set_error("Error Message Here.....");
 		  return $post;
            }
      }
     }
Nope, getting this:

Fatal error: Call to undefined method stdClass::set_error()
you are using the hook wrong by missing the parameter for the handler pointer

function test_run(&$handler)
{
    global $db,$mybb,$forum,$fid,$post,$thread;
                
    if ($forum['fid'] == 1)
          {
            $mess = $post['message'];
            
            if(strlen($mess) < 50)
            {
                $handler->set_error("Error Message Here.....");
            }
      }
} 
I'll try that later but how come this hook works fine on post replies ? How come that doesn't need the parameter ?

$plugins->add_hook("datahandler_post_validate_posts", "test_run"); 

EDIT
@paveman : I've tried that code you posted above, its not working, I get the same result as my original code.
try adding "return true;" just above the last "}"
(2012-06-18, 10:22 PM)pavemen Wrote: [ -> ]try adding "return true;" just above the last "}"

No, still not working. Its weird because Ive no problems using the following hook to trigger an error when replying to a thread, it also works without adding the parameter:

$plugins->add_hook("datahandler_post_validate_posts", "test_run");
using the parameter just means one less global pointer getting created, since the parameter being passed is the local representation of the posthandler.

looking at the code, i can't why you are having issues unless it is a priority thing conflicting with another plugin using that hook.

try
$plugins->add_hook("datahandler_post_validate_thread", "test_run", 1); 
Pages: 1 2