Displaying a simple "update successful!" message

Displaying a simple "update successful!" message

by Brad Smith -
Number of replies: 4

If I want my plugin to do $SUBJECT upon successfully saving form input, do I need to use messaging to set up a popup-only provider specific to my plugin, or is there a simpler way to just flash a brief message on the screen?

Average of ratings: -
In reply to Brad Smith

Re: Displaying a simple "update successful!" message

by David Mudrák -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators

Normally, most Moodle forms accept HTTP POST data, process them (store in the database typically) and then redirect to a page that displays the success message with a continue button (continuing automatically after several seconds usually). Typical example is posting to a forum.

I know this is quite out-fashioned these days. There is no "on-next-screen notification API" I am aware of. However, if you are redirecting the user back to a page served by your plugin, you can easily implement such support yourself. I used something like that in the workshopallocation_random plugin.

In reply to David Mudrák

Re: Displaying a simple "update successful!" message

by Fred Yankowski -

One option is to call redirect(url, message) using the optional second message parameter. That causes a simple page to display briefly (3 seconds, by default) with the message, then redirecting automatically to the given URL.

In reply to Fred Yankowski

Re: Displaying a simple "update successful!" message

by Daniel Neis Araujo -
Picture of Core developers Picture of Plugin developers Picture of Translators

If you don't like redirects (because you are allowed to ;) , you can store your messages on $SESSION or $USER and use $OUTPUT->notification() to print notifications using bootstrap classes.

Altough it is on the (much) older docs (https://docs.moodle.org/dev/Output_Components#notification) it seems to work pretty well.

In reply to Daniel Neis Araujo

Re: Displaying a simple "update successful!" message

by Fred Yankowski -

$OUTPUT->notification() is nice. I'm going to start using that. (With redirects smile ).