MyBB Community Forums

Full Version: Thread post, check field
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi guys,
I have another problem with my new plugin...
I inserted a new field in new thread page, but I don't know how to show errors, this is my code:
$plugins->add_hook("newthread_do_newthread_start", "ticon_do_newthread");
function ticon_do_newthread() {
    global $lang, $post_errors, $ticon;
    $lang->load("ticon");
    if(!empty($_FILES['ticon']['name']) && !empty($_FILES['ticon']['type'])) {
        if($_FILES['ticon']['size'] > 0) {
            $ticon = $_FILES['ticon'];
            $ext = get_extension(my_strtolower($ticon['name']));
            echo $lang->ticon_errtype;
            if(!preg_match("#^(gif|jpg|jpeg|jpe|bmp|png)$#i", $ext))
                $post_errors[] = $lang->ticon_errtype;
        }
    }
}

help Sad
1. Why are you echoing something?
2. As for $post_errors, there's no logic in your code if you take a look at these: https://github.com/mybb/mybb/blob/featur...d.php#L252 -> https://github.com/mybb/mybb/blob/featur...d.php#L395
@Destroy666 the echo was only for a test. I used $post_errors but I know that it doesn't work... What do you suggest without editing mybb files?
Error can be shown on db send data i allways send as an array to insert on db when i debugging new plugins with extra fields and sended data, if youu wish to show an error before send MyBB automatically shows if you use the error MyBB function. Otherwise if you wish to load on page shows the most usefull way i kwow is the function var_dump.
@Dark Neo I didn't understand, in what table I have to save errors?
What @Destroy666 said is correct: there's no logic in your code because $post_errors is wiped (line 395) after your code is run (line 252). You should instead use datahandler_post_validate_thread and use $this->set_error(). Beware that it is a hook by reference, you need to pass $this as an argument in order to access the class' functions and data.
Ok I'll try this. Thank you Shade.

it works thank you Shade Smile