Not Solved Datahahandler Issue
#1
Not Solved
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;
            }
	  }
 	}
Reply
#2
Not Solved
Your hook second parameter and the function name are not same.
Reply
#3
Not Solved
Thats a typo in the post sorry, thats not the issue.
Reply
#4
Not Solved
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;
            }
      }
     }
Reply
#5
Not Solved
Nope, getting this:

Fatal error: Call to undefined method stdClass::set_error()
Reply
#6
Not Solved
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.....");
            }
      }
} 
Lost interest, sold my sites, will browse here once in a while. It's been fun.
Reply
#7
Not Solved
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.
Reply
#8
Not Solved
try adding "return true;" just above the last "}"
Lost interest, sold my sites, will browse here once in a while. It's been fun.
Reply
#9
Not Solved
(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");
Reply
#10
Not Solved
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); 
Lost interest, sold my sites, will browse here once in a while. It's been fun.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)