Get FormField content links from submitted form responses

You can get the entry values of input fields in a form response.

To do this, perform the following:

  1. In the form code-behind, get an instance of the FormsManager class.
  2. Get an instance of the LibrariesManager class.
  3. Get the form by form name.
  4. Get the form response entries by form.
  5. For each form response entry, get the content links of the form response field by using the GetValue method.

Use the following code sample:

C#
using System.Linq;
using Telerik.Sitefinity.Forms.Model;
using Telerik.Sitefinity.Model;
using Telerik.Sitefinity.Model.ContentLinks;
using Telerik.Sitefinity.Modules.Forms;
using Telerik.Sitefinity.Modules.Libraries;

namespace Telerik.Sitefinity.Documentation.CodeSnippets.DevGuide.SitefinityEssentials.Modules.Forms
{
   public partial class FormsSnippets
   {
       public static void GetFormFieldContentLinksFromFormResponses(string formName, string formFieldName)
       {
           FormsManager formsManager = FormsManager.GetManager();
           LibrariesManager librariesManager = LibrariesManager.GetManager();

           //Get the Form by Name
           var form = formsManager.GetForms().Where(f => f.Name == formName).SingleOrDefault();

           //Get the FormEntries for that Form
           var records = formsManager.GetFormEntries(form);

           // Loop through all the response records for this form
           foreach (FormEntry record in records)
           {
               //Use GetValue() to obtain the fields ContentLink array
               var contentLink = record.GetValue<ContentLink[]>(formFieldName).FirstOrDefault();
               if (contentLink != null)
               {
                   var document = librariesManager.GetDocument(contentLink.ChildItemId);
               }
           }
       }
   }
}
Want to learn more?
Enhance your Sitefinity skills by enrolling in free training sessions. Become Sitefinity certified through Progress Education Community to strengthen your professional credentials.
New to Sitefinity?