Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hey Guys,
Anyone know if it's possible to hook into the On Save event in Umbraco Forms?
I had some problems with my custom fields permanently breaking forms so it would be good if I could keep and audit log type trail of the forms.
Cheers, Dave
Hi Dave,
Did you find a way. I have searched all over the place with no result.
/Rune
Would a custom workflow be a potential solution? https://our.umbraco.com/documentation/Add-ons/umbracoforms/developer/extending/adding-a-workflowtype
I wanted to clear a cache whenever a form is saved. I cannot find the usual service for that event.
Oops sorry, I thought you meant a Save event for a form submitted by a (frontend) user, doh!
OK, for a saving of a Form (in the backoffice), could try this...
using Umbraco.Core.Composing; using Umbraco.Forms.Core; using Umbraco.Forms.Core.Services; namespace Umbraco.Forms.Community { internal sealed class UmbracoFormsSavedComposer : ComponentComposer<UmbracoFormsSavedComponent> { } internal sealed class UmbracoFormsSavedComponent : IComponent { private readonly IFormService _formService; public UmbracoFormsSavedComponent(IFormService formService) { _formService = formService; } public void Initialize() { _formService.Saved += Form_Saved; } public void Terminate() { _formService.Saved -= Form_Saved; } private void Form_Saved(object sender, FormEventArgs e) { if (e.Form != null) { // Do your thang! } } } }
I haven't tested that, hopefully it'll give a good starting point. Let me know how it goes.
Cheers, - Lee
Thankyou for the great example. That should work in theory but weirdly enough none of the events I try is actually called.
I have tried these: formService.Saved += FormServiceSaved; formService.Saving += FormServiceSaving; formService.Updated += FormServiceUpdated; formService.Deleted += FormServiceDeleted;
This code is run in my CacheComponent and the formService is not null. So it should work. But the events is not being fired.
That is weird. Not sure if it's a UmbracoForms bug or if the events is not hooked up to changing the forms.
Just for good measure I tried posting a form as well, which of course did nothing.
Hi Rune,
I've had a quick play around with it, (whilst watching umbraCoffee!), and it looks like FormStorage is still being used, instead of FormService.
FormStorage
FormService
Even though the IFormStorage.Saved events are marked as deprecated, along with a message to use IFormService.Saved instead.
IFormStorage.Saved
IFormService.Saved
Here's my code snippet, which did fire when I saved an existing form.
internal sealed class UmbracoFormsSavedComponent : IComponent { private readonly IFormStorage _formStorage; public UmbracoFormsSavedComponent(IFormStorage formStorage) { _formStorage = formStorage; } public void Initialize() { _formStorage.Saved += FormStorage_Saved; } public void Terminate() { _formStorage.Saved -= FormStorage_Saved; } private void FormStorage_Saved(object sender, Umbraco.Forms.Core.FormEventArgs e) { if (e.Form != null) { // Do your thang! } } }
Hope this helps.
Ah yes. Brilliant. We have to use the deprecated ones instead.
They work as supposed to though.
I have chosen to use the to side by side. Could be that the service works in some other scenario.
Thanks for the help!
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Umbraco Forms - Hook into On Save event
Hey Guys,
Anyone know if it's possible to hook into the On Save event in Umbraco Forms?
I had some problems with my custom fields permanently breaking forms so it would be good if I could keep and audit log type trail of the forms.
Cheers, Dave
Hi Dave,
Did you find a way. I have searched all over the place with no result.
/Rune
Would a custom workflow be a potential solution?
https://our.umbraco.com/documentation/Add-ons/umbracoforms/developer/extending/adding-a-workflowtype
I wanted to clear a cache whenever a form is saved. I cannot find the usual service for that event.
Oops sorry, I thought you meant a Save event for a form submitted by a (frontend) user, doh!
OK, for a saving of a Form (in the backoffice), could try this...
I haven't tested that, hopefully it'll give a good starting point. Let me know how it goes.
Cheers,
- Lee
Thankyou for the great example. That should work in theory but weirdly enough none of the events I try is actually called.
I have tried these: formService.Saved += FormServiceSaved; formService.Saving += FormServiceSaving; formService.Updated += FormServiceUpdated; formService.Deleted += FormServiceDeleted;
This code is run in my CacheComponent and the formService is not null. So it should work. But the events is not being fired.
That is weird. Not sure if it's a UmbracoForms bug or if the events is not hooked up to changing the forms.
Just for good measure I tried posting a form as well, which of course did nothing.
/Rune
Hi Rune,
I've had a quick play around with it, (whilst watching umbraCoffee!), and it looks like
FormStorage
is still being used, instead ofFormService
.Here's my code snippet, which did fire when I saved an existing form.
Hope this helps.
Cheers,
- Lee
Ah yes. Brilliant. We have to use the deprecated ones instead.
They work as supposed to though.
I have chosen to use the to side by side. Could be that the service works in some other scenario.
Thanks for the help!
/Rune
is working on a reply...