Developer forum

Forum » Development » Form Notification subscriber - cancel/abort submit

Form Notification subscriber - cancel/abort submit

Nicholai Pedersen
Reply

Hi everyone,

I'm using the subscriber: [Subscribe(Dynamicweb.Forms.Notifications.Frontend.OnAfterSubmitSave)]
And what I'm trying to accomplish is to validate an email on form submit and if the email doesnt comply with my criteria, i wish to cancel the submit somehow. The only option I can find that seems to somewhat do what I want is:
 

if (args == null || !(args is Dynamicweb.Forms.Notifications.Frontend.OnAfterSubmitSaveArgs))
{
      return;
}

 Dynamicweb.Forms.Notifications.Frontend.OnAfterSubmitSaveArgs submitArgs = args as Dynamicweb.Forms.Notifications.Frontend.OnAfterSubmitSaveArgs;


 submitArgs.Submit.Delete();

Is this the only way or is there a better way to 'cancel' the submit if a condition is met?


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Nicholai

Hope life treats you well out west!

You can use a Notifications.Frontend.OnBeforeContent notification which gets passed a Notifications.Frontend.OnBeforeContentArgs object.

That Notifications.Frontend.OnBeforeContentArgs object has a StopExecution property that will skip the form submit.

This notification fires on all form module instances - so also when rendering a form.

So inside your notify method, do something like this to detect a submit:

if (!string.IsNullOrEmpty(RequestContext("cmd")))
{
    if (RequestContext("cmd").Equals("save", StringComparison.OrdinalIgnoreCase))
    {
        //Check the email address and fail if it is not ok:
        (Notifications.Frontend.OnBeforeContentArgs)args.StopExecution = true;
    }
}

Votes for this answer: 1
 
Nicholai Pedersen
Reply

Hi Nicolai!

Thank you a bunch for your time for this reply! that was exactly what I was looking for 👌 Life out west is going great, thank you! It was nice to see ITWatch spotlight DW - 2024 will surely be a great year with DW10 as well

hope everyone's doing well over there

Sincerely, Nicholai

 

You must be logged in to post in the forum