Creating custom form submit controller

Vote:
 

Tried implementing the example for having the custom form submit controller however doing so I get an error stating it cannot find a default controller for form submissions. How do I override and set which controller to use? 

Error Message:

Additional information: No default Instance is registered and cannot be automatically determined for type 'EPiServer.Forms.Controllers.IDataSubmitController'

Thanks!

#147657
Apr 20, 2016 16:54
Vote:
 

Sounds like you are missing a line in structuremap config?

#147701
Apr 21, 2016 15:47
Vote:
 

Sounds like something I would be missing. I have not found any sort of documentation of what and where needs changed besides adding that file. 

Any idea what I need to do exactly?

#147704
Apr 21, 2016 16:00
Vote:
 

Tried the attribute?

[ServiceConfiguration(typeof(IDataSubmitController))]

and then add a line in 

https://github.com/episerver/EPiServer.Forms.Demo/blob/master/DemoInitializationModule.cs

to map the IDataSubmitController to your implementation.

#147705
Edited, Apr 21, 2016 16:12
Vote:
 

(Was already using this)

[ServiceConfiguration(typeof(IDataSubmitController))]
    public class DemoSubmitFormController : DataSubmitController
    {
        public ActionResult Index()
        {
            return View();
        }

    }

I copied the class from your example and modified Initialize to the following: 

public void Initialize(InitializationEngine context)
        {
            _serviceConfigurationContext.Container.Configure(c =>
            {
                c.For<IDataSubmitController>().Use(new DemoSubmitFormController()); 
            });
        }

It still throws the same exception. 

#147708
Apr 21, 2016 16:51
Vote:
 

Hi,

Sorry for the missing information. In the beginning, we intended to use IDataSubmitController and StructureMap for resolving the CoreController for Forms to work. But later on, we decide to use normal ASP.NET MVC controller because it would be easier. (We might change, so the DI solution like yours would work). So last time I check (with AlloyMVC as a test website) this is true for Forms 2.0:

You can use your own controller.

  • Make a controller. GetFormInitScript() and Submit() are most important methods.
  • map the route in Global.asax RouteTable.Routes.MapRoute("DemoSubmitFormController", "demo/{controller}/{action}", new { controller = "demosubmitform" , action = "Index" });
  • Modify Forms.config (inside the modules/_protected folder)
<episerverforms ...

coreController="/EPiServer.Forms/DataSubmit"

... 

</episerverforms>

You can reconfigure the coreController to point to any ASP.NET MVC controller.

I will update the Demo project and write an article for this. Thank you.

Lockevn.

#148199
Edited, May 05, 2016 13:54
Vote:
 

Hi @Lockevn - I've successfully routed and configured forms to use a custom controller which inherits DataSubmitController.  I want to just use the base GetFormInitScript and only override the Submit action.  When the base GetFormInitScript action is called I'm getting an error (Unable to find a module by assembly '[my assembly detail]' Parameter name: moduleAssembly).  Is there some additional config to allow this to work? Thanks.

Neil

#148508
May 16, 2016 10:56
Vote:
 

Hi Neil,

The GetFormInitScript() utilizes Paths.ToResource(GetType(), "Views/FormContainerInitScript.ascx") to take the ascx template, then render the JavaScript from that template.
By default, the template is in wwwroot\modules\_protected\EPiServer.Forms\Views/FormContainerInitScript.ascx
Because your  custom controller is not in a correct "Episerver module", the Paths.ToResource() fails.

Let's say, you write your custom Controller in AlloyMVC (which is an correct "Episerver module"), DataSubmitController.GetFormInitScript() will take the view from wwwroot/Views/FormContainerInitScript.ascx

There is no more configuration.

We will change DataSubmitController.GetFormInitScript() to take view from exactly in EPiServer.Forms module (use typeof(DataSubmitController) instead of using just GetType()) . But at the moment, you have to override it totally. Sorry for this.

#148510
May 16, 2016 11:06
Vote:
 

Thanks Lockevn, I reflected it and have it working using typeof.

#148512
May 16, 2016 12:33
Vote:
 

We will change DataSubmitController.GetFormInitScript() to take view from exactly in EPiServer.Forms module (use typeof(DataSubmitController) instead of using just GetType()) . But at the moment, you have to override it totally. Sorry for this.

AFORM-665 is fixed and closed in Forms 3.0

#150151
Jun 13, 2016 8:43
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.