Try our conversational search powered by Generative AI!

How to get data in Episerver Forms Override form submit method


I have created a controller inheriting from DataSubmitController in which i have overide Submit method to execute my part of code before actually saving in the table.

My issue is i was using  base.HttpContext.Request.Form.AllKeys; to get the data which was mentioned by the user in the form but this does not show the new hidden fields(added in my custom FormContainerBlock) also it does not show the actual names of the fields i mentioned for my custom form elements instead is shows _field13213. 

Is there any other way to get the correct data in this submit method?

Jul 22, 2020 14:57

The _field13213 contains ID of the element, you can get IContent from that ID. So, name of the field (and all other metadata) can be found in the IContent.

Jul 23, 2020 3:00

So i did something like below for which i used key _FormGUID value to get the custom fields in the block:

var id = Guid.Parse(Request.Form[keys[i]]);
var content = ContentRepository.Get<IContent>(id) as Models.CustomFormBlock;

But this way it gives only that data which is present in the FormContainerBlock. But i had a custom form element inherited from TextBoxElement as well which had few hidden fields or input fields in its ascx which does not render as key during submit only the main input value can be seen in keys. I dont want to submit those fields data but i need them on server side to perform some action. 

How can i get those fields data which are not present as keys.

Jul 23, 2020 5:55

You need to render your element with the same struct with others default one. So your element will appear in submission and you can get its data.

<div class="Form__Element FormTextbox" data-f-element-name="__field_218" data-f-type="textbox">
    <label for="cd39abad-d3ed-467f-bb87-46357b6fff28" class="Form__Element__Caption">Text 1</label>
    <input name="__field_218" id="cd39abad-d3ed-467f-bb87-46357b6fff28" type="text" class="FormTextbox__Input" aria-describedby="__field_218_desc" value="" data-f-datainput="" aria-invalid="false">
    <span class="Form__Element__ValidationError" data-f-linked-name="__field_218" data-f-validationerror="" id="__field_218_desc" style="display:none"></span>

Make sure you render the data-f-element-name, data-f-datainput and <input name="__field_<your id>". Then your data will be included in the submission.

Jul 23, 2020 6:44

I don't think when you override the DataSubmitController make the validation cannot execute. Your custom element should allow Require validator and make sure you ticked on it on EditView.

Jul 23, 2020 9:29
* 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.