Developer forum

Forum » Development » Notification on forms for editors

Notification on forms for editors

Jan Sangill
Reply

Hi,

I am trying to use a notification subscriber:
Dynamicweb.DataManagement.Notifications.OnBeforeFormSave

However, when I try to save data, this is not reached.

Am i missing something?

  [Subscribe(Notifications.OnBeforeFormSave)]
    public class FormTest : NotificationSubscriber
    {
        public override void OnNotify(string notification, NotificationArgs args)
        {
            var log = LogManager.Current.GetLogger("jan");
            log.Log("Var her OnBeforeFormSave");

            Notifications.Form.OnBeforeFormSaveArgs loadedArgs = args as Notifications.Form.OnBeforeFormSaveArgs;
        }
    }


Replies

 
Kenneth Radoor
Reply

Hi

This is still an issue in v. 9.5.5.

I think it would be a great place to do some server.side validation when using Google reCAPTCHA, when using Forms for Éditors.

If anybody has a better idea or way to do it, i'm all ears.

Thanks

/Kenneth

 

 
Jan Sangill
Reply
This post has been marked as an answer

I am using: Notifications.Frontend.OnAfterSubmitSave

And doing my own formvalidation server side now.

If not validated, I delete the entry and redirect back and show errors

Votes for this answer: 1
 
Kenneth Radoor
Reply

Thanks.

I'll give that event a try.

/Kenneth

 
Nicolai Pedersen
Reply

OnBeforeFormSave is a notification from the datalist forms module - when the form settings are saved - not when the form is submitted. See https://doc.dynamicweb.com/api/html/da3ceb68-2389-5e42-b2fa-4e4ff1892d4d.htm

You can find the Forms for editors notifications here: https://doc.dynamicweb.com/api/html/e65d43d9-d4fd-dc90-ea0a-7ef859b9e4b1.htm

Sorry about the confusion.

Do you have problems with forms for editors submitted by bots - with the antispam enabled? Would like to see those examples if possible.

Thanks Nicolai

 
Kenneth Radoor
Reply

Ok but it has a bit of a strange behavoir.

After I cast the args, the method is exited. Am I missing something ?

 

This is my code:

using Dynamicweb.Extensibility.Notifications;
using Dynamicweb.Forms;

namespace Imade.DW95.Web.Tests
{
    [Subscribe(Dynamicweb.Forms.Notifications.Frontend.OnAfterSubmitSave)]
    public class FormOnAfterSubmitSaveCustom : NotificationSubscriber
    {
        public override void OnNotify(string notification, NotificationArgs args)
        {
            if (args == null) {
                return;
            }

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


            // execution of method is exited before the next line 
            if (onAfterSubmitSaveArgs != null)
            {
                var good = "This is  never reached";
            }
            else {
                var error = "This is also never reached";
            }
        }
    }
}

 
Nicolai Pedersen
Reply

Well - it would be a miracle to be able to make that method exit half way thorugh!

I cannot see why that should not work - it "works on my machine"...

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Maybe you are debugging against an older version of the DLL? Then the runtime doesn't have those blocks of code so you would never hit them. Check that the file in your bin matches the one you're debugging in VS.

 
Kenneth Radoor
Reply

It was an issue with running the code in the debugger. Not sure what it is, but doing some good old logging to text files got me the results i wanted.

The above code is OK, and im now able to do the extra validation with Google reCAPTCHA.

Thanks all for your time and input.

/Kenneth

 
Nicolai Pedersen
Reply

Hi Kenneth

You never answered if this form has problem with bots? Really would like to see the issue...

BR Nicolai

 
Kenneth Radoor
Reply

Hi Nicolai

I will send you a mail, as it gets to custommer specific to discus here.

/Kenneth

 

You must be logged in to post in the forum