I am building a new web portal using umbraco (just upgraded to the latest version) and I have some custom controllers and views which I am using to display the form
(for reference, the form is being rendered in the view using:
The form is appearing as I would expect but when I try to submit the form, rather than my local RecordSubmittedNotification handler being fired, a POST request is being made to the original controller. Any ideas as to why the RecordSubmittedNotification handler isn’t being fired?
I can happily provide more details and code if required
Are you registering the notification handler correctly in either an IComposer or within the IUmbracoBuilder on your startup/program.cs?
Also what is the purpose of the notification handler could it be better suited to use a custom workflow with the form instead? for instance, if your sending data to a 3rd party system.
For a notification It should be something like the following:
Notification handler:
public class MyRecordSubmittedNotificationHandler : INotificationHandler<RecordSubmittedNotification>
{
public void Handle(RecordSubmittedNotification notification)
{
//your code
}
}
Hmm I’ve just tested this on a fresh install and the notification works correctly for me?
One thing I did find based on your example is that I got an exception to be thrown when using the generic ILogger interface without specifying the type so could you be running from a previous successful build?
the correct syntax would be ILogger<FormSubmittedHandler> logger
This is the code I used:
public class FormNotificationComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
builder.AddNotificationHandler<RecordSubmittedNotification, FormSubmittedHandler>();
}
}
public class FormSubmittedHandler(ILogger<FormSubmittedHandler> logger) : INotificationHandler<RecordSubmittedNotification>
{
public void Handle(RecordSubmittedNotification notification)
{
logger.LogInformation("TestNotification triggered.");
var test = notification;
}
}
It seemed that setting “includeScripts = true” resolved this problem (not sure if it created further problems though). However, we now have another problem where we have a form with multiple pages; when you try to traverse to the next page it invokes a post request rather than either validating or rendering the next page on the form
For reference, we are using jQuery validation (and the validation works on single page forms)
This might be your issue if you are rendeing jquery/validate/validate.unobtrusive in the footer (after the inline form scripts) so not available to the formscript?
The problem isn’t really with the scripts (for extra validation; this is now working), it is that the next page of the form simply fails to load. We hit the POST request on the form handler rather than our personalised FormNotificationComposer and we do not understand why this is happening. This is the same problem we were having previously, but it was occuring on the submission of a single page; setting the includeScripts = true seemed to bypass this one particular error but is not helping us now
Could it be that you are subscribing to a RecordSubmittedNotification… and that perhaps only fires on record submission at the end of a multi stage form?
And as you aren’t able to get to the final submit it wouldn’t fire?
Also I think these NotificationHandlers are actually callbacks and not replacements for the core handler.. so you’d see both happening?