liam@goldfinch ~/blog · main
Back to posts · ~/blog/posts/unique-form-submissions-in-kentico-12-mvc.md

Unique form submissions in Kentico 12 MVC

When adding forms to websites, there may be occasions where you might prefer to restrict form respondents from making multiple form submissions.

When adding forms to websites, there may be occasions where you might prefer to restrict form respondents from making multiple form submissions. It could be that your form represents a method of signing up for an event, registering interest in a topic or webinar, or you might simply prefer that the same email address isn't associated with multiple form submissions.

This topic popped up recently as a question on the Questions & Answers section of the Xperience DevNet portal. If you are new to developing Xperience websites, or you find you are having trouble implementing a certain feature of Xperience, then I highly recommend submitting questions on the Q&A section of DevNet. You can get really good solutions and detailed explanations from the Xperience community, including answers from Xperience MVPs and members of the Kentico Support team.

The solution

For this question in particular, I provided sample code which can be used in your Xperience MVC site. This module intercepts a form submission, checks for fields containing the keyword email, and compares the values submitted against values from other submissions to find a match.  If it finds a match then the form submission is cancelled and an error is displayed, otherwise the form continues to process as you would expect.  You can find the sample code below:

using CMS;
using CMS.DataEngine;
using CMS.OnlineForms;
using DancingGoat.GlobalEvents;
using System.Linq;

[assembly: RegisterModule(typeof(FormGlobalEventsModule))]
namespace DancingGoat.GlobalEvents
{
    public class FormGlobalEventsModule : Module
    {
        public FormGlobalEventsModule() : base("DancingGoat.FormGlobalEventsModule")
        {
        }

        protected override void OnInit()
        {
            base.OnInit();

            // Register custom events
            BizFormItemEvents.Insert.Before += Insert_Before;
        }

        private void Insert_Before(object sender, BizFormItemEventArgs e)
        {
            var item = e.Item;

            // Sanity check to ensure we actually have a bizform item.
            if (item == null)
            {
                return;
            }

            // Get all column names that contain email.
            var columnNames = item.ColumnNames.Where(x => x.ToLowerInvariant().Contains("email"));

            // Loop over all column names containing the keyword email.
            foreach (var columnName in columnNames)
            {
                // Get the submitted email address value.
                var email = item.GetStringValue(columnName, string.Empty);

                // Lookup the current bizform for submissions with the same field value.
                var existingEntry = BizFormItemProvider.GetItems(e.Item.BizFormClassName)
                    .Column(columnName)
                    .TopN(1)
                    .WhereEquals(columnName, email)
                    .FirstOrDefault();

                // If it already exists, cancel it (displays an error on the MVC site).
                if (existingEntry != null)
                {
                    e.Cancel();
                }
            }
        }
    }
}
// related

Keep reading

how-ai-changed-the-shape-of-delivery-on-a-real-kentico-project.md
#post

How AI Changed the Shape of Delivery on a Real Kentico Project

A real‑world case study exploring how AI‑assisted workflows changed decision‑making, reduced uncertainty, and accelerated delivery during an Xperience by Kentico rebuild.

from-design-system-to-deployed-code-a-weekend-with-claude-design.md
#post

From design system to deployed code: a weekend with Claude Design

A practical experiment in using Claude Design to infer a design system from an existing site, explore a redesign within real constraints, and move straight into implementation without the usual design handoff.

from-spec-to-stripe-building-a-payment-provider-for-xperience-by-kentico.md
#post

From Spec to Stripe: Building a Payment Provider for Xperience by Kentico

How a Markdown spec and AI tools like ChatGPT and Claude Code helped me build a Stripe payment provider for Xperience by Kentico - faster, cleaner, and spec-driven from the start.

how-i-used-claude-code-to-redesign-my-kentico-sustainability-module.md
#post

How I Used Claude Code to Redesign My Kentico Sustainability Module

Discover how I used Claude Code, Anthropic’s AI coding assistant, to refactor and redesign the UI of my Kentico Sustainability module - replacing third-party components with native ones and creating a cleaner, more integrated experience.