MyBB Community Forums
Thread post, check field - Printable Version

+- MyBB Community Forums (https://community.mybb.com)
+-- Forum: Extensions (https://community.mybb.com/forum-201.html)
+--- Forum: Plugins (https://community.mybb.com/forum-73.html)
+---- Forum: Plugin Development (https://community.mybb.com/forum-68.html)
+---- Thread: Thread post, check field (/thread-195674.html)



Thread post, check field - chack1172 - 2016-07-14

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


RE: Thread post, check field - Destroy666 - 2016-07-15

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/feature/newthread.php#L252 -> https://github.com/mybb/mybb/blob/feature/newthread.php#L395


RE: Thread post, check field - chack1172 - 2016-07-15

@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?


RE: Thread post, check field - Whiteneo - 2016-07-15

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.


RE: Thread post, check field - chack1172 - 2016-07-16

@Dark Neo I didn't understand, in what table I have to save errors?


RE: Thread post, check field - Shade - 2016-07-16

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.


RE: Thread post, check field - chack1172 - 2016-07-16

Ok I'll try this. Thank you Shade.

it works thank you Shade Smile