0

I'm trying to customize my user profile twig template UX to be a little more user friendly, but I can't figure out where to find what the built-in default errors/notices flash messages for the users/save-user form…

Any pointer in the right direction most appreciated!

1 Answer 1

1

These are flash messages which are typically triggered by controllers when saving or performing an action.

Craft::$app->getSession()->setFlash();
Craft::$app->getSession()->setError();

https://docs.craftcms.com/api/v3/craft-web-session.html#public-methods

Or in Craft CMS 3.5+ when used in a Controller action, you don't need to call the session service and can simply do.

$this->setSuccessFlash()
$this->setFailFlash()

In Twig this component is also available using:

{% do craft.app.session.setFlash() %}
{% do craft.app.session.setError() %}
2
  • Maybe I didn't ask my question clearly enough, sorry… What I'm trying to find out is what flash messages are sent by a form using users/save-user by default. Do I need to find the related controller and dig through the code or is it documented somewhere? I'm more of a frontend person, so I'm not super clear on where to find that controller… But I'll try to dig in the code. Thanks!
    – Yann
    Jul 19 at 22:08
  • @Vann Ah right, easiest way to find that would be the code. The controller can be found: github.com/craftcms/cms/blob/develop/src/controllers/…, if for Craft CMS 4, change develop to v3 in the URL for Craft CMS 3, then look for the actionSaveUser function, then where there are setFailFlash() and setSuccessFlash(), those are the flash messages being displayed at various stages and conditions. Jul 20 at 19:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.