XForm: How do I set default settings in an XForm

Vote:
 

In "Edit Form" mode for an XForm there are 2 check boxes for "

How can I set these 2 check boxes to be set by default every time you create a new XForm?!

#77906
Nov 28, 2013 10:51
Vote:
 

No builtuin way as far as I now. I think you would need to modify the EPiServer dialogs directly.

#77909
Nov 28, 2013 10:58
Vote:
 

Although possible to reflect the code, add new vpp mappings for the new aspx files etc to add this functionality it's not recommended in any way.

I rewote parts of xform for EPiServer 5 because of some severe performance bugs in that version. It will however make it much more difficult to upgrade, maintain the site so don't go down that road unless you really (x 10) have to. Suggest it as a feature in next version instead and simply tell the customer that it's not supported with xforms yet

#77913
Nov 28, 2013 11:16
Vote:
 

Hi Robert,

I agree with Per and Daniel that no offical way (simpler way) to do that.

You can workaround as below:

        void PageBase_PageSetup(PageBase page, PageSetupEventArgs e)
        {
            if (IsXFormEditPage())
            {
                page.PreRender += page_PreRender;
            }
        }

        void page_PreRender(object sender, EventArgs e)
        {
            var page = sender as PageBase;
            if (IsCreatingNewForm(page))
            {
                var formAnonymousPostControl = page.FindControl<CheckBox>("FormAnonymousPost");
                var formMultiplePostControl = page.FindControl<CheckBox>("FormMultiplePost");
                formAnonymousPostControl.Checked = true;
                formMultiplePostControl.Checked = true;
            }
        }

        private bool IsXFormEditPage()
        {
            var request = HttpContext.Current.Request;
            var appRelativePath = request.AppRelativeCurrentExecutionFilePath;
            var xformEditVirtualPath = string.Format("{0}{1}", Settings.Instance.UIUrl, "Edit/XFormEdit.aspx");
            return VirtualPathUtility.Equals(appRelativePath, xformEditVirtualPath);
        }

        private bool IsCreatingNewForm(PageBase page)
        {
            return page != null && string.IsNullOrEmpty(page.Request["formid"]) && !page.IsPostBack;
        }

        

in your InitalizeModule or Global.asax

Hope that help!

Ha Bui

#78010
Edited, Dec 02, 2013 4:34
Vote:
 

Hi!

Thanks for your replies! I have solved it by adding the following code:

    [InitializableModule]
    public class XFormInitializationModule : IInitializableModule
    {
        public void Initialize(InitializationEngine context)
        {
            XFormControl.ControlSetup += ControlSetup;
        }

        public void Uninitialize(InitializationEngine context)
        {
            XFormControl.ControlSetup -= ControlSetup;
        }

        public void Preload(string[] parameters)
        {
            
        }

        private static void ControlSetup(object sender, EventArgs e)
        {
            ((XFormControl) sender).ControlsCreated += ControlsCreated;
        }

        private static void ControlsCreated(object sender, EventArgs e)
        {
            var form = sender as XFormControl;
            if (form != null && form.EditMode)
            {
                if (string.IsNullOrEmpty(form.FormDefinition.FormName))
                {
                    form.FormDefinition.AllowMultiplePost = true;
                    form.FormDefinition.AllowAnonymousPost = true;
                }
            }
        }
    }

     

Comments?!

#78039
Edited, Dec 02, 2013 14:10
Vote:
 

Cool! Work as a charm! Conglatulations!

/Ha Bui

#78064
Dec 03, 2013 5:08
Vote:
 

Looks like a nice solution :)

#78067
Dec 03, 2013 9:58
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.