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?
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.
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.
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.
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.