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

After submitting a Shared Form View, how do I show the green success message?

Development and Programming

dmDev08's avatar
dmDev08
100 posts
10 years ago
dmDev08's avatar dmDev08

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.

       
dmDev08's avatar
dmDev08
100 posts
10 years ago
dmDev08's avatar dmDev08

It appears to work if I change defer() to now().

Why is that?

(Also, there’s no documentation on this. I found out how to do this by doing a search into the code, but the code uses defer)

       
Kevin Cupp's avatar
Kevin Cupp
791 posts
10 years ago
Kevin Cupp's avatar Kevin Cupp

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

       
dmDev08's avatar
dmDev08
100 posts
10 years ago
dmDev08's avatar dmDev08
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.

       

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.