x First time here? Check out the FAQ
  • Avatar11posts58karma

    Custom NoSpam Workflow

    jason mitchell started this topic June 28, 2011 @ 08:04

    I've created a no spam workflow and figured I'd just post it here to help others with a similar issue.

    Basically, all this workflow does is check to see if a hidden field is modified from its default value and either deletes the record, does nothing with it, or approves it.

    Set your form to manual approval for this to work, and move your workflow steps around accordingly.  This workflowtype should go inside the on submit event.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Umbraco.Forms.Core;
    using Umbraco.Forms;
    using System.Web.UI.WebControls;
    using Umbraco.Forms.Core.Enums;
    
    namespace Umbraco.Forms.Core
    {
        public class NoSpam : Umbraco.Forms.Core.WorkflowType
        {
            [Umbraco.Forms.Core.Attributes.Setting("Spam Field Label Name",
                description = "The label used for no spam hidden control",
                control = "Umbraco.Forms.Core.FieldSetting.TextField")]
            public string NoSpamLabel { get; set; }
    
            [Umbraco.Forms.Core.Attributes.Setting("Spam Field Default Value",
                description = "The set value for the no spam hidden control",
                control = "Umbraco.Forms.Core.FieldSetting.TextField")]
            public string NoSpamValue { get; set; }
    
            [Umbraco.Forms.Core.Attributes.Setting("Action", prevalues = "Delete Record, Do Nothing",
                description = "What to do if it matches",
                control = "Umbraco.Forms.Core.FieldSetting.Dropdownlist")]
            public string Action { get; set; }
    
            public NoSpam()
            {
                this.Id = new Guid("31804252-AD24-4755-B040-2DE0282D893C");
                this.Name = "Perform filtering if the no spam field is modified/removed";
                this.Description = "Changes the state of the record being processed";
            }
    
            public override List<Exception> ValidateSettings()
            {
                return new List<Exception>();
            }
    
            public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e)
            {
                bool spam = false;
    
                RecordField nospamField = record.RecordFields.Values.Where(value => value.Field.Caption == NoSpamLabel).FirstOrDefault();
                if (nospamField == null || nospamField.ValuesAsString() != NoSpamValue)
                    spam = true;
    
                Umbraco.Forms.Core.Services.RecordService rs = new Umbraco.Forms.Core.Services.RecordService(record);
    
                if (spam)
                {
                    if (Action == "Delete Record")
                        rs.Delete();
                }
                else
                {
                    rs.Approve();
                }
    
                rs.Dispose();
    
                return WorkflowExecutionStatus.Completed;
            }
        }
    }
    

  • Sebastiaan Janssen posted this reply June 28, 2011 @ 10:23

    Great, this one was on my list to do! Would you mind if I added it to the Contour Contrib project? You can add it yourself as well if you want, just ask to be a contributor on the right hand side (blue block) and don't forget to mention your Codeplex username so I can give you access there as well.


  • Avatar11posts58karma
    Comment with ID: 81478
    jason mitchell posted this reply June 29, 2011 @ 03:10

    I just sent over a message with my codeplex username.

     

    Also, I can't seem to edit my own post to update the thread to reflect some changes I've made.


  • Sebastiaan Janssen posted this reply June 29, 2011 @ 09:52

    Thanks Jason, I've added you to the project.

    Editing posts is being worked on, it works on all but the opening post. The source will be in Codeplex soon anyway, thanks Jason!


  • Avatar11posts58karma
    Comment with ID: 81601
    jason mitchell posted this reply June 29, 2011 @ 04:45

    Seb, I've included the the workflowtype and have included the validation and cleaned up the source a bit.

    Feel free to modify at your will.

     


Please login or Sign up To post replies