Need to automatically add additional data as part of submitted data

Vote:
 

Is it possible to override the event for submitting form data so that any extra information is added to the SubmissionData.Data and becomes viewable in "form submissions". I want to add some logic that automatically adds social security number for authenticated users, every time a form is posted.

I'm gonna try a custom hiddenfield or textbox form element and assign the ssn back-end.

#194889
Edited, Jul 05, 2018 15:30
Vote:
 

Hi,

Unfortunately I don't think you can add in any additional fields which don't exist in your form definition but there are a few things you can do. The simplest method would be to create a custom form element which inherits HiddenElementBlockBase like this:

    [ContentType(GUID = "00000000-1111-2222-3333-0123456789AB",
        DisplayName = "Hidden User ID",
        GroupName = "BasicElements",
        Order = 1,
        AvailableInEditMode = true)]
    public class UserIdElement : HiddenElementBlockBase
    {
        public override void SetDefaultValues(ContentType contentType)
        {
            base.SetDefaultValues(contentType);

            // Set the field value here
            PredefinedValue = MyUser.GetTheIDValue();
        }
    }

This works fine for one or two types of data to add but, over time, can result in a bunch of specific form elements with only one use. A similar alternative is to use the "Hidden Visitor Profiling" element and create your own custom data source for it as shown here:
https://github.com/episerver/EPiServer.Forms.Demo/blob/master/Implementation/VisitorData/DemoVisitorDataSource.cs

Each of the methods above require the editor creating the form to manually create/add those fields but, if you need a given field to appear on all forms and you can't trust your editors to do this manually, you could tie into the content creation and publishing events for the form and add in those fields programmatically if they don't already exist.

Hope that helps.

#194900
Edited, Jul 05, 2018 19:13
* 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.