{flash}
The flash messages of this request - set with padFlash on the page before - one occurrence each.
Syntax
{flash} {$message} {$type} {/flash}
{flash} ... @else@ ... {/flash}
{flash 'error'} {$message} {/flash}
Parameters
-
type -
Optional: only the messages of this type -
error,info(padFlash's default) or any word the application uses.
Description
A flash message is said on one request and shown on the next: the page that took a post calls padFlash ( 'Thanks, your message was sent.' ) and redirects, and the page the browser lands on shows it with {flash}. That is the post-redirect-get pattern, without a ?sent=1 in the address that anyone could put in a link.
{flash} iterates the messages of this request, one occurrence each, with {$message} and {$type} - padFlash's second argument, info by default. {flash 'error'} takes only the messages of that type and leaves the others for a later {flash}. No message, and the @else@ half renders.
Each message is shown once: a second {flash} does not show it again. A message lives exactly one request after the one that flashed it, shown or not; one flashed during this very request shows at once, as in the examples here. A padFlash cookie tells the next request there is something to take, so pages of an application that never flashes do not open the session.
Examples
Messages and their type
One occurrence per message, with $message and $type - flashed in this very request, so they show here at once.
{flash}
<p class="notice {$type}">{$message}</p>
@else@
<p>No messages.</p>
{/flash}
<?php
padFlash ( 'Your order was saved.' );
padFlash ( 'The coupon has expired.', 'error' );
?>
Your order was saved.
The coupon has expired.
One type first
{flash 'error'} takes the errors only; a {flash} after it shows what is left.
<ul class="errors">
{flash 'error'}<li>{$message}</li>{/flash}
</ul>
{flash}<p>{$message} ({$type})</p>{/flash}
<?php
padFlash ( 'The e-mail address is missing.', 'error' );
padFlash ( 'Draft kept.' );
padFlash ( 'The phone number is missing.', 'error' );
?>
- The e-mail address is missing.
- The phone number is missing.
Draft kept. (info)
Post, redirect, show
The page that took the post flashes and redirects; the page the browser lands on shows the message once.
{# save.php: padFlash ( 'Thanks, your message was sent.' ); padRedirect ( 'contact' ); #}
{# contact.pad - the next request: #}
{flash}
<p class="notice {$type}" role="status">{$message}</p>
{/flash}
See also
- {form} A form that posts back to the page, carrying the session's CSRF token and its own name, its fields refilling when it came back.
- {redirect} Sends the browser to another page or address with a 302 and ends the request.