2012-06-19, 08:38 AM
Pages: 1 2
2012-06-19, 09:05 AM
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:
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');
}
}
}
2012-06-19, 09:07 AM
Try this;
It should work. Make sure you add correct forum id in;
---
Edit: I've not seen Tomm M's code. I checked and tested mien and it works.
$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.
2012-06-19, 09:14 AM
Yaldaram; yours will work because $mybb->input['message'] is always less than 50 characters - $mybb needs to be added to the global declaration.
2012-06-19, 09:17 AM
You're correct Tom Moore. Amazingly I forgot to add global object
2012-06-19, 09:20 AM
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.
2012-06-19, 09:38 AM
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.
2012-06-19, 03:29 PM
sorry I missed the $data = $handler->data; bit.
your original code would have worked has it used
$mess = $handler->data['message']; instead of $post
your original code would have worked has it used
$mess = $handler->data['message']; instead of $post
2012-06-19, 05:58 PM
(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
2014-01-09, 06:09 PM
Guys how to add a hook to validate editpost.php
Pages: 1 2