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.
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.
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?
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.
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.
Give it a try, the default Forms view engines accept both ascx and cshtml. So copy it to your view folder should work.