MyBB Community Forums

Full Version: $post->set_error()
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

I am playing around and I want to know how you can get those little alert boxes if something in the message is wrong.

In datahandlers.php there is a set_error() function that I saw used elsewhere, but it doesn't return anything, and it requires an error code argument, and I don't know if I have to insert/register the error code somewhere, or whether I can just call it what I want.

I am just playing around with the post datahandler - new post, update post and new thread, and I want to have an error occur if certain criteria is not matched when I submit a new post.

So....any help would be appreciated, thanks.


P.S - do error messages automatically happen for quick reply (JS alert) or do you have to manually do them?
P.P.S - I am hooking in through "datahandler_post_insert_post"
You should generally set errors in the validation step (datahandler_post_validate_post), not in the insertion hook.

The set_error function takes the langvar name as the argument, which means you need it to be set before the errors get displayed. If you don't want to load it from a language file, you can manually load in the langvar, example:
 global $lang;
 $lang->myerror = "This is an error.";
You rock. You rock hard.

Good to see it does Javascript as well Big Grin

Love ya'