MyBB Community Forums

Full Version: Generating inline_error()
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Hi guys,

I think it's with the inline_error() function but I can't seem to get it working.

How would I generate the following with a custom message?

http://i.imm.io/Btbn.png

For example:

if ($foo != $bar)
{
inline_error("foo doesn't equal bar!");
}
else
{
// something else
}

I've tried using the inline_error() function but it doesn't appear to be working. I've globalised $mybb, what else would I need to do?

Cheers Smile
$error = '';
if($foo != true)
{
     $error = array('$foo is no true, please try again.');
}
$errors = ($error ? inline_error($error) : '');

And put {$errors} in your template.

Edit: Please note that if it will be only one plain error, it doesn't need to be a array. (Also fixed function name there.)
Cheers Omar

I'm getting this: http://i.imm.io/BtoM.png

I'm using it in newreply_do_newreply_start

Cheers
If it is only one error message, you can try this simple one:
$errors = '';
$foo or ($errors = inline_error('$foo is no true, please try again.'));

It the problem persists, please paste your code here, since I see no reason for it even in my first code.
This is what I was using:

global $mybb, $errors;
    session_start();
$error = '';
if ($_POST["rand_code"] != $_SESSION["rand_code"] OR $_SESSION["rand_code"]=='')  { 

     $error = array('$foo is no true, please try again.');
$errors = ($error ? inline_error($error) : '');
} else { 
     // add form data processing code here 
     echo  '<strong>Verification successful.</strong>'; 
}
echo $_SESSION["verify"];
}

Cheers Smile
I cleaned it for my tastes, anyways, try this:
global $mybb, $errors;

session_start();
$errors = '';
if($mybb->input['rand_code'] != $_SESSION['rand_code'] OR $_SESSION['rand_code'] == ''){
	$errors = inline_error('$foo is no true, please try again.');
}else{
	// add form data processing code here 
	echo '<strong>Verification successful.</strong>'; 
}
echo $_SESSION["verify"];

This is supposing you want to use $errors outside your function, otherwise you can just echo the in-line error (you are already echoing the "successful" message anyways).
Thanks Omar, I'll give that a go.

One other question:

When using this:
if($mybb->input['rand_code'] != $_SESSION['rand_code'] OR $_SESSION['rand_code'] == ''){
    $errors = inline_error('$foo is no true, please try again.');

}else{
    // add form data processing code here 
    echo '<strong>Verification successful.</strong>'; 
}

Even if the if statement is true, the whole form processes, meaning the new reply is posted regardless of the if statement.

How can I kill the script but still output the page as adding die(); before else { outputs a blank page.

Thanks
It all depends on how you are handling your function, for example this one:
function validate_input()
{
	global $mybb;
	session_start();

	if($mybb->input['rand_code'] != $_SESSION['rand_code'] || !$_SESSION['rand_code']){
		$errors = inline_error('$foo is no true, please try again.');
		return false;
	}else{
		return true;
	}
}

Now on your script, you do something like this:
if(!($valid = validate_input()))
{
	// validation was false, there is a message to show
	echo $valid;
	// you can kill the procces with exit; here
}else{
	// add form data processing code here 
	echo '<strong>Verification successful.</strong>';
	// the script will conitnue unless using exit; here
}
Thanks Omar

I'm using:

function keepproxyout_newreply_do_newreply_start(){
function validate_input()
{
    global $mybb;
    session_start();

    if($mybb->input['rand_code'] != $_SESSION['rand_code'] || !$_SESSION['rand_code']){
        $errors = inline_error('$foo is no true, please try again.');
        return false;
    }else{
        return true;
    }
}
if(!($valid = validate_input()))
{
    // validation was false, there is a message to show
    echo $valid;
    exit;
}else{
    // add form data processing code here 
    echo '<strong>Verification successful.</strong>';
    // the script will conitnue unless using exit; here
}
}

but when I use exit; it outputs a white page.

Thanks Smile
You shouldn't be defining functions inside functions. Why don't you use error(); to output the error message?

if(!($valid = validate_input()))
{
    error($valid);
}
Pages: 1 2 3