Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • jason mitchell 11 posts 68 karma points
    Jun 28, 2011 @ 20:04
    jason mitchell
    2

    Custom NoSpam Workflow

    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 5060 posts 15522 karma points MVP admin hq
    Jun 28, 2011 @ 22:23
    Sebastiaan Janssen
    0

    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.

  • jason mitchell 11 posts 68 karma points
    Jun 29, 2011 @ 03:10
    jason mitchell
    0

    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 5060 posts 15522 karma points MVP admin hq
    Jun 29, 2011 @ 09:52
    Sebastiaan Janssen
    0

    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!

  • jason mitchell 11 posts 68 karma points
    Jun 29, 2011 @ 16:45
    jason mitchell
    0

    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 Sign in or register to post replies

Write your reply to:

Draft