Custom Form Container Block with form fields already on the template

Vote:
 

Is there a way to create a custom form container block and have a set of fields already on the form. 

I.e I'd want all new forms created to have name, address fields already on there that I have chosen in code.  Then I'd have a content area below those fields that editors can drag and drop the fields on using the GUI?  

Another form I need to create is so besoke it would be easier to create as a separate form, but how would I get the fields to be actual form fields that get saved?  I understand you can add properties to a form, but these are not ones that are actually submitted as part of the form, just used to help display or style it.

Any ideas?  I've struggled to find anything online about this.

#185106
Nov 09, 2017 13:53
Vote:
 

It is a little bit complex. You can add more ContentArea to your custom FormContainerBlock, then hook to CreatedContent event (in IContentEvents) for intializing your elements (add your predefined elements to your ContentArea...). Replace FormBusinessService with overriding the mehtod GetFormElementBlocks() to include your pre-defined elements when form rendered (so they will be submitted as part of your form). Last thing you need to do is that modify FormContainerBlock.ascx to display the form as you want.

Hope this help.

#185171
Nov 10, 2017 8:23
Vote:
 

I must admit I don't fully understand what you mean.  So I'd be able to state which fields element blocks I'd want, so my new custom form elements?  Then in my view I can add those elements to it manually?

We're using razor for our views so I can't just use that ascx file.  What's the best approach, copy the formcontainerblock out into where I'm putting my custom form field views Shared\ElementBlocks and try and convert to razor?

#185191
Nov 10, 2017 14:34
Vote:
 

You only need to modify view of FormContainerBlock in case you want to customize displaying of your pre-choosen elements, otherwise leave it as default.

#185218
Edited, Nov 13, 2017 7:08
Vote:
 

It's not in razor format though which are are using.  I'm not sure I can just copy the ascx file into my views with all my cshtml files?  I need to be able to tweak some of the html.

#185224
Nov 13, 2017 9:48
Vote:
 

Give it a try, the default Forms view engines accept both ascx and cshtml. So copy it to your view folder should work.

#185225
Nov 13, 2017 10:00
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.