title: Umbraco custom validation form fields (confirmaton)
body: <p>I'd like to write a simple confirm email validation field in a form, what's the best way? here is my code till now, just a basic form. For confirmationEmail field I'd like to have a real time validation like the email field, not only on submit as I did:</p>
  
  <p>controller</p>
  
  <pre><code> public class ContactController : SurfaceController
  {
  
      /// &lt;summary&gt;
      /// Renders the Contact Form
      /// @Html.Action("RenderContactForm","ContactFormSurface");
      /// &lt;/summary&gt;
      /// &lt;returns&gt;&lt;/returns&gt;
      public ActionResult Index()
      {
          //Return a partial view ContactForm.cshtml in /views/ContactFormSurface/ContactForm.cshtml
          //With an empty/new ContactFormViewModel
          return PartialView("Contact", new Contact());
      }
  
      [HttpPost]
      public ActionResult Send(Contact Model)
      {
  
          //Check if the dat posted is valid (All required's &amp; email set in email field)
          if (!ModelState.IsValid)
          {
              //Not valid - so lets return the user back to the view with the data they entered still prepopulated                
              return CurrentUmbracoPage();
          }
  
          //Check if the dat posted is valid (All required's &amp; email set in email field)
          if (Model.Email != Model.ConfirmEmail)
          {
              //Not valid - so lets return the user back to the view with the data they entered still prepopulated                
              return CurrentUmbracoPage();
          }
  
          //Update success flag (in a TempData key)
          TempData["IsSuccessful"] = true;
  
          TempData["Name"] = Model.Name;
          TempData["Email"] = Model.Email; 
  
          //All done - lets redirect to the current page &amp; show our thanks/success message
          return RedirectToCurrentUmbracoPage();
  
      }
  
  }
  </code></pre>
  
  <p>model</p>
  
  <pre><code> namespace CribisWeb.Models
  {
  public class Contact
      {
          [Required]
          [DisplayName("Nome")]
          public string Name { get; set; }
  
          [Required]
          [EmailAddress]
          [DisplayName("Email")]
          public string Email { get; set; }
  
          [Required]
          [EmailAddress]
          [DisplayName("Conferma Email")]
          public string ConfirmEmail { get; set; }
  
      }
  }
  </code></pre>
  
  <p>view</p>
  
  <pre><code>    @model CribisWeb.Models.Contact
  
  @if (Convert.ToBoolean(TempData["IsSuccessful"]))
  {
      &lt;h1&gt;YAY!&lt;/h1&gt;
      &lt;p&gt;Thanks for sending your message, we will get back to you shortly.&lt;/p&gt;
      &lt;p&gt;
          @TempData["Name"]
          @TempData["Email"]
      &lt;/p&gt;
  }
  else
  {
      using (Html.BeginUmbracoForm&lt;CribisWeb.Controllers.ContactController&gt;("Send"))
      {
      @Html.ValidationSummary(true)
  
      &lt;div&gt;
  
          &lt;br /&gt;
          @Html.LabelFor(x =&gt; x.Name)
          @Html.TextBoxFor(x =&gt; x.Name)
          @Html.ValidationMessageFor(x =&gt; x.Name)
          &lt;br /&gt;
          @Html.LabelFor(x =&gt; x.Email)
          @Html.TextBoxFor(x =&gt; x.Email)
          @Html.ValidationMessageFor(x =&gt; x.Email)
          &lt;br /&gt;
          @Html.LabelFor(x =&gt; x.ConfirmEmail)
          @Html.TextBoxFor(x =&gt; x.ConfirmEmail)
          @Html.ValidationMessageFor(x =&gt; x.ConfirmEmail)
          &lt;br /&gt;
      &lt;/div&gt;
      &lt;input type="submit" value="Submit" class="btn-accept" /&gt;
      }
  
     }
  </code></pre>
  
  <p>THANKS</p>