XForm, MVC, preserving input values after custom validation

 

Hi!

I've managed to build nice little custom validation for my MVC/XForm page. I added recaptcha validation which works nicely. But what doesn't work is that all the input-fields in the form are blank after validation fails (for example, user hasn't provided valid email). I want those fields to contain the same value user entered after post.

Here's some code. This is from the view. Model.Page.Form property contains the XForm object.

@Html.PropertyFor(m => m.Page.Form, new { XFormParameters = new EPiServer.XForms.Util.XFormParameters() { PostAction = "Post", SuccessAction = "Success", FailedAction = "Failed"} })

    

This is from the controller.

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult Post(FormPage currentPage, XFormPostedData xFormPostedData)
        {
            VerifyRecaptcha()
            if (ModelState.IsValid)
            {
                var data = new XFormPageHelper().GetXFormData(this, xFormPostedData);
                XFormActionHelper.DoAction(data, xFormPostedData, true);
                return Success(currentPage, currentPage);
            }
            return Failed(currentPage, xFormPostedData);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult Success(FormPage currentPage, XFormPostedData xFormPostedData)
        {
            return Redirect("/to/other/page");
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult Failed(FormPage currentPage, XFormPostedData xFormPostedData)
        {
            return Index(currentPage);
        }

    

How do I tell XForm object to render user posted data back to user in Failed-method?

#65751 Feb 07, 2013 14:15
  •  

    Btw. There's a bug in the code above. Don't mind it.

    return Success(currentPage, currentPage);

    Should be

    return Success(currentPage, xFormPostedData);

    I had to clean up the code and just copypasted it incorrectly.

    #65752 Feb 07, 2013 14:20
  •  

    It seems that XFormPageUnknownActionHandler was the answer.

    #65764 Feb 08, 2013 7:03
  • Sayeed Choudhury
    Member since: 2012
     

    Hi Marko

    Could you please send some details on how you used the XFormPageUnknownActionHandler?

    #78933 Dec 05, 2013 10:54