Default form elements with predefined value for a Custom form container block

Vote:
 

In order to passthrough few common prefined input values based on the form utilized, is there a way to default to automatically create a form container block with form elements. 

I got Salesforce connector add on and I need to send few hidden values for each form created among visible input fields mapped. So, if there is a way to default the form elements as part of form container block then it is less time for editors to create a predefined hidden field form element when every time they want to create a new custom form container block. 

#258962
Jul 14, 2021 23:22
Vote:
 

Hi Arun

Do you have these fields added to every single form created ever? If so then you can hook into the CreatedContent event, check if the content type is a form container and then add the fields yourself.

The alterantive approach is to create a custom form container block using the code below:

using EPiServer.DataAbstraction;
using EPiServer.DataAnnotations;
using EPiServer.Forms.Core;
using EPiServer.Forms.Implementation.Elements;
using EPiServer.ServiceLocation;

namespace Example.FormExample
{
    [ContentType(
         DisplayName = "Salesforce form container", 
         GUID = "16660C0A-5129-4E6C-85C0-E16161842F2D", 
         GroupName = "FormsContainerElements")]
    [ServiceConfiguration(typeof(IFormContainerBlock))]
    public class SalesforceFormContainerBlock : FormContainerBlock
    {
        public override void SetDefaultValues(ContentType contentType)
        {
            base.SetDefaultValues(contentType);

            //Add custom elements here
        }
    }
}

This then allows editors to select the form type they want and retains the ability t create non-Salesforce specfic forms as shown below:

#258964
Jul 15, 2021 7:45
Vote:
 

Hi David, 

Thanks for the reommendation.Sorry if i didnt explain the challenge I am facing properly, I am trying to default form element blocks rather form fields in my case I need to add 2 predefined hiddenItem blocks as part of the custom form container block when created by default

#259006
Edited, Jul 16, 2021 1:30
* 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.