1

I have a frontend form where images can be uploaded.

I am handling the image moderation within EVENT_BEFORE_HANDLE_FILE on the Asset class. I am setting session errors for any moderation issues detected.

This is all working great, however I need a way of stopping the image uploading if errors are detected, but I want the session errors to continue to show as the page refreshes.

What is the best way to stop the image upload in this event, but for it to still set the session errors?

Thanks

1

From investigating, the issue could not be resolved at the time of writing this answer. Even though the EVENT_BEFORE_HANDLE_FILE on the Asset class extends the cancelable event, there was not actually a way to cancel.

To answer the question, there is currently no nice way of being able to cancel this event.

I raised a ticket to add this feature, you can follow its progress here https://github.com/craftcms/cms/issues/6875

This would allow you to use $event->isValid = false; in the scenario any tests fail and you didn't want the image to continue being handled by Craft.

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.