Is there a way to throw a validation exception but with NO flash message?

I use this code in my ajax handle for a form:

if ($validator->fails()) {
         throw new ValidationException($validator);
      } else { ... }

But I capture the errors below each form field using a

<span data-validate-for="..."></span>

So I would like that the upper red flash message wouldn’t appear.

Sorry, I found the solution myself, but I post it here just in case someone finds it helpfull.
I was adding the “data-request-flash” to the form. Just by removing it, the flash message is not shown, but the proper errors do.

1 Like

but i think there is still a problem, after a successfull form submission, I would have liked to show a flash success message and by removing data-request-flash, it wont work.

Oh, I see your point. I hadn’t spotted that cause in my forms I use to redirect to a thank you page after succesfull submission. I don’t know if there’s a way then to throw the exception without flash message.

@daft is there a way to do this? I’d like to handle the errors with NO flash, just using the <span data-validate-for="..."></span> but still do show a flash message on success. Example, a newsletter subscription form, where a redirection would be overkill.

There is a potential solution for this coming in v3.2… The data-request-flash attribute has been improved so you can specify which messages to display. For example, to only show success and warning flash messages:

data-request-flash="success,warning"
1 Like

Hello @daft
Yes I see its working on normal pages
but If I write this code inside the rainlab.pages, it does not work and same problem appears.