I am working on an application where I created a form using sitecore forms. When the user submits the form, It should read all the fields from the forms and add it to XML element and post the XML payload to an webservice end point.

I am trying to create a custom submit action to achieve this. Any related code which will help me to go forward.


1 Answer 1


Welcome to Sitecore Stack Exchange. You should first take a look at the sitecore documentation on how to create a custom submit action https://doc.sitecore.com/en/developers/93/sitecore-experience-manager/walkthrough--creating-a-custom-submit-action.html. Depending on your approach you would need to read all submitted fields in the custom action, either by field name

protected override bool Execute(SendMailActionData data, FormSubmitContext formSubmitContext)
    Assert.ArgumentNotNull(formSubmitContext, nameof(formSubmitContext));
    var yourField = formSubmitContext.Fields.FirstOrDefault(f => f.Name.Equals("FieldName"));
    if (yourField != null)
        var property = yourField?.GetType().GetProperty("Value")?.GetValue(yourField).ToStringOrEmpty();

or if you have complex types in your form like lists you can use a generic method similar to the one shown https://madhuanbalagan.com/generic-method-to-read-values-from-any-type-of-form-fields.

I would also recommend to take a look at the submit action examples implemented in the sitecore forms extension module https://github.com/bartverdonck/Sitecore-Forms-Extensions/tree/master/src/Feature/FormsExtensions/code/SubmitActions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.