Copied to clipboard

Flag this post as spam?

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


  • rs82uk 10 posts 73 karma points
    Oct 26, 2015 @ 16:19
    rs82uk
    0

    Compare fields Validation

    Hi there we are building a registration form in umbraco, and we want the user to confirm their email address, so require validation to compare both Email and Confirm Email textboxes, is this possible if so, I would be grateful for a steer in the right direction.

  • Comment author was deleted

    Oct 26, 2015 @ 16:31

    Yup you can hook into the event model and add extra validation rules

    Here is how to do it with Contour http://www.nibble.be/?p=430

    For Forms it's similar but the controller lives in a different namespace, think it's Umbraco.Forms.Web.Controllers...

  • rs82uk 10 posts 73 karma points
    Oct 27, 2015 @ 08:54
    rs82uk
    0

    Hi Tim, We couldn't get this to work in umbraco 7.2 with Umbraco Forms

  • Comment author was deleted

    Oct 27, 2015 @ 09:26

    It should be similar, it's just the controller that lives in a different namespace so use Umbraco.Forms.Web.Controllers.UmbracoFormsController

  • Steve 140 posts 321 karma points
    Oct 27, 2015 @ 14:04
    Steve
    0

    @rs82uk, try this:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using Umbraco.Core;
    using Umbraco.Core.Events;
    using Umbraco.Core.Logging;
    using Umbraco.Core.Models;
    using Umbraco.Core.Services;
    using Umbraco.Forms;
    
    public class ContourValidation : ApplicationEventHandler
    {
        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            Umbraco.Forms.Web.Controllers.UmbracoFormsController.FormValidate += FormRenderController_FormValidate;
    
        }
    
        void FormRenderController_FormValidate(object sender, Umbraco.Forms.Mvc.FormValidationEventArgs e)
        {
            if (e.Form.Name == "FormWithExtraValidation")
            {
                var s = sender as Controller;
                if (s != null)
                {
                    var pwf = e.Form.AllFields.SingleOrDefault(f => f.Caption == "Password").Id.ToString();
                    var rpwf = e.Form.AllFields.SingleOrDefault(f => f.Caption == "Repeat password").Id.ToString();
    
                    var password = e.Context.Request[pwf];
                    var repeatpassword = e.Context.Request[rpwf];
    
                    if (password != repeatpassword)
                        s.ModelState.AddModelError(rpwf, "passwords don’t match");
    
                }
            }
        }
    }
    
  • Steve 140 posts 321 karma points
    Dec 04, 2015 @ 20:28
    Steve
    0

    Apologies to Tim - I just realized that my post did not indicate the source of the code. I definitely can't take any credit for this! It's Tim's code and on his website at http://www.nibble.be/?p=430
    Steve

Please Sign in or register to post replies

Write your reply to:

Draft