Posted on 23/04/2024 15:58:40
Hi Martin
That would be too late in the process as the submit has already been added to DB.
You can use Notifications.Frontend.OnBeforeContent:
using Dynamicweb.Extensibility.Notifications;
using Dynamicweb.Notifications;
using System;
namespace Dynamicweb.Examples.Notifications
{
[Subscribe(Dynamicweb.Forms.Notifications.Frontend.OnBeforeContent)]
public class FormSubscriber : NotificationSubscriber
{
public override void OnNotify(string notification, NotificationArgs args)
{
if (args == null)
return;
var loadedArgs = (Dynamicweb.Forms.Notifications.Frontend.OnBeforeContentArgs)args;
if (loadedArgs != null && loadedArgs.ContentModule.RequestContext("cmd").Equals("save", StringComparison.OrdinalIgnoreCase))
{
bool submitNotAllowed = false;
//Logic to test what is being submitted
//submitNotAllowed=true
if (submitNotAllowed)
{
loadedArgs.StopExecution = true;
loadedArgs.Output = "<h1>Not allowed</h1>";
}
}
}
}
}