I know I can do this, but just can’t find in any of the docs where.
I have the following lines of code in an action if a model doesn’t save:
`
flash.put(‘danger’,‘There was a problem posting the Advertisement. Please check the information you are attempting to submit and try again.’);
return renderView(“employmentads/new”);
`
In my employmentads/new view, I need the flash to output, but of course it doesn’t as it won’t until the next event.
Can anyone tell me how I get flash to become current for the current event, rather than waiting till the next? As mentioned, I know I have seen somewhere that this can be done, but just can’t find anywhere.
Hi Andrew, the logic that is to access the Flash is actually in the layout. I have the following code in my layout to render out any flash notices that may exist
`
#flash.get(flashKey)#
`
So when I complete an action, I can save a message to the flash, the flow goes to the next event and the flash message is displayed to the user.
In some cases, where (as in this case) there was a problem handling a users form submission, I want to show them the form, populated with what they submitted, and an error message via the flash. The problem is, as I am rendering the view as part of the current action, the flash does not get rendered. To do this, I need some way of telling the flash to render in the same event it is declared in, rather than waiting for the next event.
I thought I had read somewhere about some setting in the flash, but maybe I dreamt it…
Wouldn’t the messagebox be better suited for error messages?
With the flashput you could have used inflatetoprc, then in the view you could have used the prc and only use the flash in the setnextevent if the messagebox doesn’t work.
Or you could pass in the second condition or the false condition you could pass saveNow = true so it becomes
flash.put(name = ‘success’, value = 'There was a problem posting the Advertisement. ', saveNow = true);