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
No, still doesn't work. I've no other plugins installed so conflict shouldn't be an issue.
I can't help but think that you're mixing your hooks. You're using validate_thread but looking for $post['message'], which is only available in the validate_post hook.

Consider this version instead:

$plugins->add_hook('datahandler_post_validate_post', 'test_run');
$plugins->add_hook('datahandler_post_validate_thread', 'test_run');

function test_run(&$handler)
{
	$data = $handler->data;

	if($data['fid'] == 2)
	{
		if(my_strlen($data['message']) < 50)
		{
			if(!$data['tid'])
			{
				$handler->set_error('Error occurred creating your thread');
			}
			elseif($data['tid'])
			{
				// We must have an existing post
				$handler->set_error('Error occurred replying to this thread');
			}

			// Shorten
			//($data['tid']) ? $handler->set_error('Error occurred replying to this thread') : $handler->set_error('Error occurred creating your thread');
		}
	}
}
Try this;
$plugins->add_hook("datahandler_post_validate_thread", "test_run");
$plugins->add_hook("datahandler_post_validate_post", "test_run");
function test_run(&$post)
{
    global $forum, $mybb;
                
    if ($forum['fid'] == 2)
          {
            $mess = $mybb->input['message'];
            
            if(strlen($mess) < 50)
            {
                  $post->is_validated = false;
          $post->set_error("Error Message Here.....");
           return $post;
            }
      }
     }

It should work. Make sure you add correct forum id in;
if ($forum['fid'] == 2)

---
Edit: I've not seen Tomm M's code. I checked and tested mien and it works.
Yaldaram; yours will work because $mybb->input['message'] is always less than 50 characters - $mybb needs to be added to the global declaration.
You're correct Tom Moore. Amazingly I forgot to add global object Blush
Oh, and regardless, is_validated is always set to true after your plugin function has finished as it is modified after the plugin hook in the datahandler. It is a marker to say the post/thread has ran through the validate function.
Tried Tomm M's example, works perfectly. That was a little more complicated than was expected. Thank you to everyone in this thread who helped, +1.
sorry I missed the $data = $handler->data; bit.

your original code would have worked has it used

$mess = $handler->data['message']; instead of $post
(2012-06-19, 03:29 PM)pavemen Wrote: [ -> ]sorry I missed the $data = $handler->data; bit.

your original code would have worked has it used

$mess = $handler->data['message']; instead of $post

Thanks paveman Wink
Guys how to add a hook to validate editpost.php
Pages: 1 2