Copied to clipboard

Flag this post as spam?

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


  • Neil Hodges 338 posts 987 karma points
    Mar 27, 2014 @ 17:14
    Neil Hodges
    0

    Creating Password repeat/confim validation within a Contour form

    Hi

    So ive created a form in Contour, it's a register form and creates a Member upon clicking on submit. I have tested this with one password field and it works great but my client would like a repeat/confirm password box and it to validate before submission.

    I have created the form using the Contour tools instead of the code first approach and wondered if there was an easy way to do this validation without re writing the whole form using the code first approach?

     

  • Comment author was deleted

    Mar 27, 2014 @ 17:24

    So Code first add an easy way of doing this but if you don't want to design your form in code you can hook into the event model and add extra errors into the controller modelstate

    So you'll need to look at http://our.umbraco.org/Documentation/Reference/Events/application-startup

    And the event you need is  Umbraco.Forms.Mvc.Controllers.FormRenderController.FormValidate

    The sender will be the controller so you can access the modelstate there and do stuff like

     ModelState.AddModelError(field.Id.ToString(),

                                             string.Format(errorMessage.ParsePlaceHolders(), field.Caption));

  • Comment author was deleted

    Mar 27, 2014 @ 17:36

    Will add a code sample tomorrow , need to run now

  • Neil Hodges 338 posts 987 karma points
    Mar 27, 2014 @ 17:44
    Neil Hodges
    0

    Ok so i have

            protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
            {
                Umbraco.Forms.Mvc.Controllers.FormRenderController.FormValidate += FormRenderControllerOnFormValidate;
            }
    
            private void FormRenderControllerOnFormValidate(object sender, FormViewEventArgs formViewEventArgs)
            {
                ModelState.AddModelError(field.Id.ToString(),string.Format(errorMessage.ParsePlaceHolders(), field.Caption));
            }

     

    Do you know where ModelState is imported from?

    I'll have a play around with it and see if i can get it working, failing that i'll wait for your code sample tomorrow.

    Thanks Tim appreciate your help.

  • Comment author was deleted

    Mar 27, 2014 @ 17:55

    Yeah the sender is the controller, so cast to controller and then you should be able to access the modelstate

  • Neil Hodges 338 posts 987 karma points
    Mar 27, 2014 @ 18:16
    Neil Hodges
    0

    Ok cool, getting closer

    protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
            {
               FormRenderController.FormValidate += FormRenderControllerOnFormValidate;
            }
    
            private void FormRenderControllerOnFormValidate(object sender , FormViewEventArgs formViewEventArgs)
            {
                //ModelState.AddModelError(field.Id.ToString(),string.Format(errorMessage.ParsePlaceHolders(), field.Caption));
                var s = sender as Controller;
                if (s != null)
                {
                    s.ModelState.AddModelError(field.Id.ToString(), string.Format(errorMessage.ParsePlaceHolders(), field.Caption));
                }
                
            }

     

    how to get the field.Id, is this the id of the Confirm Password field?

    errorMessage.ParsePlaceHolders() doesnt resolve either

     

     

     

     

     

     

     

     

     

  • Neil Hodges 338 posts 987 karma points
    Mar 28, 2014 @ 10:53
    Neil Hodges
    0

    Hi Tim

    Am i getting any closer on this? Don't suppose youve had time to knock an example together for me have you?

    Cheers

    Neil.

  • Comment author was deleted

    Mar 28, 2014 @ 11:11

    on it :)

  • Comment author was deleted

    Mar 28, 2014 @ 11:11

    Will have a working example in 30 mins 

  • Neil Hodges 338 posts 987 karma points
    Mar 28, 2014 @ 11:15
    Neil Hodges
    0

    Nice one, thanks Tim, apreciate it.

  • Comment author was deleted

    Mar 28, 2014 @ 11:39

    Here are the details http://www.nibble.be/?p=430

  • Ricardo 24 posts 56 karma points
    Oct 17, 2014 @ 10:45
    Ricardo
    0

    What is the best way to do the same type of validations (related form fields) but from Javascript (using Umbraco 4.11.9 and Contour 3.0.6)? Is there any example showing where to hook without to hack?

Please Sign in or register to post replies

Write your reply to:

Draft