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.
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");
}
}
}
}
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
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.
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...
Hi Tim, We couldn't get this to work in umbraco 7.2 with Umbraco Forms
It should be similar, it's just the controller that lives in a different namespace so use Umbraco.Forms.Web.Controllers.UmbracoFormsController
@rs82uk, try this:
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
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.