I have a situation where I want to display an alert to the user when they load my add-on’s settings screen if certain conditions are met. To do this, I’m using a now()
alert call. e.g.
if($vars['token_status'] == 'error')
{
ee('CP/Alert')->makeInline('shared-form')
->asWarning()
->withTitle(lang('da_existing_token_error_heading'))
->addToBody(lang('da_existing_token_error'))
->cannotClose()
->now();
}
But I’m also redirecting back to this same screen after I save some settings, and in that save method, I’m deferring a success message:
ee('CP/Alert')->makeInline('shared-form')
->asSuccess()
->withTitle(lang('da_token_saved_heading'))
->addToBody(lang('da_token_saved_desc'))
->defer();
The issue is that sometimes I’ll need to display both alerts on the same screen, each generated by a different method (one at runtime, one before a redirect) - but it appears as though the existence of any now()
alerts removes any previous defer()
alerts - is that correct? And if so, any way around this?
Hi Derek,
It looks like you are using the shared form as your view. By default that will load the alert saved as shared-form
, but it can also take a extra_alerts
parameter, which should be an array naming any and all other alerts you’d like to display on the page. When you do this, you’ll need to match the string you pass to makeInline()
.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.