MyBB Community Forums

Full Version: Inline Error (Plugin Building) Incorrect Placement
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm attempting to create an inline error for if the checkdate registers incorrect formatting. It works but the inline error ({$error}, {$errors}, OR {$inline_errors} all tried) is displaying at the top of the page AND where it should be (below the date input)... and I'm not sure where I messed up here lol. Whats at the top of the page is what I assumed the correct placement (below date) would look like. And showing at the top of the page shouldn't be happening at all...

As always, help and tips are always appreciated!

Here is the checkdate code:
if(!checkdate($date_month, $date_day, $date_year)) {
    $error = 'You have entered an invalid date format.';
    echo inline_error($error);
}
You don't want to be directly echoing anything out anywhere, the HTML is all rendered at the end of the code execution, so anything you echo directly will be output above the opening <html> tag. You just need to call inline_error() and it will automatically be displayed above the content block you already have.
I attempted to replace it with these codes, all tried, all made the page throw "This page isn't working" errors. Perhaps I'm misunderstanding how to alert with an error.

if(!checkdate($date_month, $date_day, $date_year)) {
    inline_error();
}

if(!checkdate($date_month, $date_day, $date_year)) {
    $error = 'You have entered an invalid date format.';
    echo inline_error();
}

if(!checkdate($date_month, $date_day, $date_year)) {
    $error = 'You have entered an invalid date format.';
    inline_error();
}



Due to my minimal PHP knowledge and not quite understanding how the error system works, I've decided to do an alternative route and add pattern parameters to the input's themselves through HTML.

For anyone in the future looking for a fix like this for inputs that should only include whole DIGITS here you go:
pattern="[0-9]{1,5}"
^ add to your input html element
The code you had was right, you just don't need to echo it

inline_error($error);
(2022-06-29, 11:56 PM)Matt Wrote: [ -> ]The code you had was right, you just don't need to echo it

inline_error($error);

Thanks, I'll keep this saved for next time. Smile