Try our conversational search powered by Generative AI!

XForm, MVC, preserving input values after custom validation



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.

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

        public virtual ActionResult Success(FormPage currentPage, XFormPostedData xFormPostedData)
            return Redirect("/to/other/page");

        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?

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.

Feb 07, 2013 14:20

It seems that XFormPageUnknownActionHandler was the answer.

Feb 08, 2013 7:03

Hi Marko

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

Dec 05, 2013 10:54
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.