Ejemplo n.º 1
0
 private void FormModelOnBeforeAddToIndex(FormModel sender, FormEditorCancelEventArgs formEditorCancelEventArgs)
 {
     if(sender.AllValueFields().Any(f => f.HasSubmittedValue && f.SubmittedValue.Equals("bad", StringComparison.InvariantCultureIgnoreCase)))
     {
         formEditorCancelEventArgs.Cancel = true;
         formEditorCancelEventArgs.ErrorMessage = "Bad values are not accepted.";
     }
 }
Ejemplo n.º 2
0
 private string RaiseBeforeAddToIndex(IPublishedContent content)
 {
     if(BeforeAddToIndex != null)
     {
         try
         {
             var cancelEventArgs = new FormEditorCancelEventArgs(content);
             BeforeAddToIndex.Invoke(this, cancelEventArgs);
             if(cancelEventArgs.Cancel)
             {
                 Log.Info("The form submission was valid, but it was not added to the index because an event handler for BeforeAddToIndex cancelled the submission.");
                 return cancelEventArgs.ErrorMessage ?? "The form submission was cancelled by the BeforeAddToIndex event handler.";
             }
         }
         catch(Exception ex)
         {
             // an event handler failed - log error and continue
             Log.Error(ex, "An event handler for BeforeAddToIndex threw an exception.");
         }
     }
     return null;
 }