Generating inline_error()
#11
Cheers Omar

Is this correct?

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;
    }
}

function verify_newreply_do_newreply_start(){
if(!($valid = validate_input()))
{
    error($valid);
exit;
} 
else{
    // add form data processing code here 
    echo '<strong>Verification successful.</strong>';
    // the script will conitnue unless using exit; here
}
}

That seems to work ok, is there a way I could use inline_error() though as I'd like to inform the user that they've failed the verification where it'd usually say "The message is missing".

Thanks Smile
[Image: information.gif] MyBB Support Technician
Please do not PM me for support.


MyBBatically - A quick and easy way to update your board!
Reply
#12
Quote:Is this correct?

You are returning true or false for $valid so there wouldn't be really any text to show.

You will need to change:
error($valid);

To:
error(inline_error('$foo is no true, please try again.'));

Quote:That seems to work ok, is there a way I could use inline_error() though as I'd like to inform the user that they've failed the verification where it'd usually say "The message is missing".

I can't see an easy way to accomplish so using the newreply_do_newreply_start hook. However you may want to check the datahandler_post_validate_post hook, which runs when validating posts.

$plugins->add_hook('datahandler_post_validate_post', 'our_hook');

function our_hook(&$dh)
{
    global $mybb;
    session_start();

    if($mybb->input['rand_code'] != $_SESSION['rand_code'] || !$_SESSION['rand_code']){
	global $lang;

	isset($lang->foo_no_true) or $lang->foo_no_true = '$foo is no true, please try again.';
	$dh->set_error('foo_no_true'); // Thi will set an error to be shown in-line with other possible post errors.
    }
}

That would be the basic. There are probably more factors to consider, like whether this hook applies only to replies or not (thread's posts).

One extra reason to use the datahanlder hook, is that your plugin will affect quick edits as well (AFAIK).
Soporte en Español

[Image: signature.png]

Discord at omar.gonzalez (Omar G.#6117); Telegram at @omarugc;
Reply
#13
Thanks Omar

I replaced the validate_input function with the code you provided above but I'm receiving this error:

Call to a member function set_error() on a non-object

Cheers
[Image: information.gif] MyBB Support Technician
Please do not PM me for support.


MyBBatically - A quick and easy way to update your board!
Reply
#14
You've to add $db as global object.
Reply
#15
Cheers Yaldaram

I've now got this:
function validate_input(&$dh)
{
    global $mybb, $db, $lang;
    session_start();

    if($mybb->input['rand_code'] != $_SESSION['rand_code'] || !$_SESSION['rand_code']){

    isset($lang->foo_no_true) or $lang->foo_no_true = '$foo is no true, please try again.';
    $dh->set_error('foo_no_true'); // Thi will set an error to be shown in-line with other possible post errors.
    }
}

but I'm still getting: Fatal error: Call to a member function set_error() on a non-object

Thanks Smile
[Image: information.gif] MyBB Support Technician
Please do not PM me for support.


MyBBatically - A quick and easy way to update your board!
Reply
#16
(2012-08-22, 08:33 AM)Vernier Wrote: Thanks Omar

I replaced the validate_input function with the code you provided above but I'm receiving this error:

Call to a member function set_error() on a non-object

Cheers

Are you sure you are hooking at datahandler_post_validate_post? It will no work at newreply_do_newreply_start.

(2012-08-22, 08:56 AM)Yaldaram Wrote: You've to add $db as global object.

$db has nothing to do here.
Soporte en Español

[Image: signature.png]

Discord at omar.gonzalez (Omar G.#6117); Telegram at @omarugc;
Reply
#17
I'm using:

function validate_input(&$dh)
{
    global $mybb, $db, $lang;
    session_start();

    if($mybb->input['rand_code'] != $_SESSION['rand_code'] || !$_SESSION['rand_code']){

    isset($lang->foo_no_true) or $lang->foo_no_true = '$foo is no true, please try again.';
    $dh->set_error('foo_no_true'); // Thi will set an error to be shown in-line with other possible post errors.
    }
}

then calling the function:

function keepproxyout_newreply_do_newreply_end(){
if(!($valid = validate_input()))
{
    error('Please go back and check your input.');
exit;
} 
else{
    // add form data processing code here 
    echo '<strong>Verification successful.</strong>';
    // the script will conitnue unless using exit; here
}
}

Hooks:
$plugins->add_hook('newreply_do_newreply_start', 'keepproxyout_newreply_do_newreply_end');
$plugins->add_hook('datahandler_post_validate_post', 'validate_input');

Cheers Smile
[Image: information.gif] MyBB Support Technician
Please do not PM me for support.


MyBBatically - A quick and easy way to update your board!
Reply
#18
Drop the newreply_do_newreply_start hook, stick to the datahandler_post_validate_post one. validate_input(); seems right to me, you no longer need keepproxyout_newreply_do_newreply_end();.
Soporte en Español

[Image: signature.png]

Discord at omar.gonzalez (Omar G.#6117); Telegram at @omarugc;
Reply
#19
Cheers Omar

I'm actually validating several things, not just new reply.

I'm validating:

New Replys
New Threads
New Private Messages
New Registration

Will that hook work?

If I used validate_input as datahandler_post_validate_post, where should I put the code I had in the newreply_do_newreply_end() function?

Thanks Smile
[Image: information.gif] MyBB Support Technician
Please do not PM me for support.


MyBBatically - A quick and easy way to update your board!
Reply
#20
You don't need what is in your keepproxyout_newreply_do_newreply_end(); function, since you are already setting a datahandler error, which will be nicely shown along other generic errors.

I'm no entirely if sure the same function will work in all those places (it all depends on what you want to validate), but I would stick to the hooks provided in the datahandler files for what it seems you want to accomplish.

New Replys => datahandler_post_validate_post
New Threads => datahandler_post_validate_thread
New Private Messages => datahandler_pm_validate
New Registration => datahandler_user_validate
Soporte en Español

[Image: signature.png]

Discord at omar.gonzalez (Omar G.#6117); Telegram at @omarugc;
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)