Episerver Forms - Programatically add data to a submission

Vote:
 

Is there a way to programatically add a form data field to a form? I don't mean a custom form element / view, but rather a data field within the data submission that can be populated by code rather than a user input

For example - I want to capture some additional data in a form submission which is calculated based on the forms position in the page tree.

The only way I can see to do it, is to create a custom field element that has no view mode display, then hook into a Form Finalised / Submitting event to run some logic to populate the value in the data submission. However this then means an editor has to add that custom form element to the form. I'd rather it just happened magically.

I'm guessing that the form data shape / schema is created at publish time on the form container block. Could I hook in there and remap the form with my additional fields?

#182087
Edited, Sep 08, 2017 17:11
Vote:
 

Can you create a custom actor to achieve your goal, as you have acess to the HttpRequest object?

http://world.episerver.com/documentation/developer-guides/forms/implementing-a-customized-actor/

#182127
Sep 11, 2017 14:05
Vote:
 

Hi Mark,

We had a similar requirement to meet and went for the last option you mentioned. Forms are just content so you can tie in to the datafactory events. In our case we wanted to make sure that the fields were always added including retrospectively so we tied in to the CreatedContent, CheckingInContent and PublishingContent events to check whether the relevant fields had been added and, if not, added them (there's a ContentArea called ElementsArea which holds the form fields).

I did look into whether you could dynamically add data after the form had been posted in the way that you could with XForms but I couldn't find anything.

Hope that helps,

Paul

#182142
Sep 11, 2017 16:38
* 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.