We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

How do you provide an error message using a plugin?

Development and Programming

Mark Bowen's avatar
Mark Bowen
12,637 posts
16 years ago
Mark Bowen's avatar Mark Bowen

Hi there,

Was just wondering if there is an easy way to provide an error message from within a plugin?

Say for instance I have the following :

{exp:my_plugin plugin_parameter="name"}
{name}
{/exp:my_plugin}

Let’s just say that whatever the site creator places as the plugin_parameter=”name” is not valid then what do you do to let them know?

If this was say querying the database and bringing back a result or in this case not bringing back a result then would you even provide an error message as that would stop the use of the template wouldn’t it?

Just wondering what the best way to go about it all is?

Thanks.

Best wishes,

Mark

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
16 years ago
Mark Bowen's avatar Mark Bowen

Also meant to ask one other question on this.

Let’s say I had this plugin code :

{exp:my_plugin plugin_parameter="{member_id}"}
{name}
{/exp:my_plugin}

If I want to use the {member_id} global variable as the value for the plugin parameter then when I do this in a plugin :

$member_id = $TMPL->fetch_param('member_id');

I don’t get the member_id returned if I try to echo out the value passed, instead I just get {member_id} exactly like that with the braces spat out.

I know I can do this :

$member_id = $SESS->userdata['member_id'];

but I don’t want to, I need to be able to use global variables instead. Is this not possible?

Best wishes,

Mark

       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

Hi Mark,

Was just wondering if there is an easy way to provide an error message from within a plugin?

May be that isn’t correct, but I provide error messages in my plugins using simple PHP echo statements, as here:

echo 'ERROR! The value of parameter "name" of exp:my_plugin tag is invalid.';

Such message gets printed on top of the screen - exactly as needed.

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
16 years ago
Mark Bowen's avatar Mark Bowen

Hiya,

Yep I know about echo but as far as I know that indeed isn’t the right way to do things. I’m sure that there is a function which will put a box on the screen with the error in it. Not too big of a deal though because if someone has made an error in a tag anyway then any error is better than none I suppose 😉

Best wishes,

Mark

       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

Hi Mark,

Yep I know about echo but as far as I know that indeed isn’t the right way to do things. I’m sure that there is a function which will put a box on the screen with the error in it.

Is it really echo wrong way to display error message? General Style and Syntax guidelines does not say anything about how error messages should be displayed.

Box on the screen with a message is not much better than error message displayed using echo statement. Echo statement even seems to be better since when error is displayed in a box the rest of the page isn’t rendered; and echo statement does not prevent the rest of the page being rendered.

       
Yuri's avatar
Yuri
273 posts
16 years ago
Yuri's avatar Yuri

Hey Mark,

try this for error output:

global $OUT, $LANG;
      
$LANG->fetch_language_file('my_plugin');
      
if ($error) 
{
return $OUT->show_user_error('general', $LANG->line('my_error_message'));
}

Of course, you’ll need to have lang.my_plugin.php in your language files and string corresponding to ‘my_error_message’ in it.

BTW, did you find any way to pass {member_id} as plugin parameter??

       
Yuri's avatar
Yuri
273 posts
16 years ago
Yuri's avatar Yuri

For passing {member_id} as plugin parameter, I did this:

if ($subject_id=="{member_id}"||$subject_id=="{logged_in_member_id}") 
      {
      global $SESS;
      $subject_id = $SESS->userdata['member_id'];  
    }

however I’m sure there’s more proper way.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.