Thread post, check field
#1
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
My Projects - Support My Projects

Don't forget to rate posts!
Reply
#2
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
Reply
#3
@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?
My Projects - Support My Projects

Don't forget to rate posts!
Reply
#4
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.
The only infinite thing is the universe and human stupidity, but the universe is not for sure

Plugins 1.6.x

Plugins 1.8.x

Reply
#5
@Dark Neo I didn't understand, in what table I have to save errors?
My Projects - Support My Projects

Don't forget to rate posts!
Reply
#6
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.
[Image: fSGNVQj.png]
Reply
#7
Ok I'll try this. Thank you Shade.

it works thank you Shade Smile
My Projects - Support My Projects

Don't forget to rate posts!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)