When I’ve created a Shared Form View and the user has submitted it (and it passed validation and was saved to the DB), how do I then show the green box with a custom success message? (Just like when they publish a channel entry change)
Here’s what I tried:
ee( "CP/Alert" )->makeInline( "myalert" )
->asSuccess()
->withTitle( "Test Title" )
->addToBody( "Test Body" )
->defer();
//Then before outputting, add it to vars
$vars += array(
"alerts_name" => "myalert"
);But this didn’t work. It never shows the alert.
defer() will show the banner after a redirect, which is best practice after a successful permission so you don’t refresh the page and resend the POST request. If you scroll down a bit in the code you found, you’ll see we’re redirecting the request. now() will show the alert in the same request, better for showing validation errors where you’re loading the page based on POST data.
There is documentaiton on this here: https://ellislab.com/expressionengine/user-guide/development/services/alert.html
defer()will show the banner after a redirect, which is best practice after a successful permission so you don’t refresh the page and resend the POST request. If you scroll down a bit in the code you found, you’ll see we’re redirecting the request.now()will show the alert in the same request, better for showing validation errors where you’re loading the page based on POST data. There is documentaiton on this here: https://ellislab.com/expressionengine/user-guide/development/services/alert.html
Thanks. I read that but misunderstood the documentation wording. It says, “Defers rendering and displaying of the alert until the next CP request.” But since “CP” is also a service name, I thought that referred to an “ee( “CP…” ) request like buildling a form, etc. I didn’t realize it meant http request.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.