Umbraco Forms
CMSCloudHeartcoreDXP
15.latest
15.latest
  • Umbraco Forms Documentation
  • Legacy Documentation
  • Release Notes
  • Installation
    • Installing Umbraco Forms
    • Licensing
  • Upgrading
    • Upgrading Umbraco Forms
    • Version Specific Upgrade Notes
  • Editor
    • Creating a Form - The basics
      • Form Settings
      • Form Advanced Options
      • Form Information
      • Overview Of The Field Types
        • Date
        • File Upload
        • reCAPTCHA V2
        • reCAPTCHA V3
      • Setting-up Conditional Logic on Fields
    • Attaching Workflows
      • Workflow Types
    • Viewing And Exporting Entries
    • Defining And Attaching Prevalue Sources
      • Prevalue Source Types Overview
  • Developer
    • Property Editors
    • Preparing Your Frontend
    • Rendering Forms
    • Rendering Forms Scripts
    • Themes
    • Custom Markup
    • Email Templates
    • Working With Record Data
    • Umbraco Forms in the Database
    • Extending
      • Adding A Type To The Provider Model
        • Setting Types
      • Adding A Field Type To Umbraco Forms
        • Excluding a built-in field
      • Adding A Prevalue Source Type To Umbraco Forms
      • Adding A Workflow Type To Umbraco Forms
      • Adding An Export Type To Umbraco Forms
      • Adding a Magic String Format Function
      • Adding A Server-Side Notification Handler To Umbraco Forms
      • Adding a Validation Pattern
      • Customize Default Fields and Workflows For a Form
    • Configuration
      • Forms Provider Type Details
    • Webhooks
    • Security
    • Magic Strings
    • Health Checks
      • Apply keys and indexes
      • Apply keys and indexes for forms in the database
    • Localization
    • Headless/AJAX Forms
    • Block List Labels
    • Field Types
    • Storing Prevalue Text Files With IPreValueTextFileStorage
  • Tutorials
    • Overview
    • Creating a Contact Form
    • Creating a Multi-Page Form
Powered by GitBook
On this page
  • Available Methods
  • GetApprovedRecordsFromPage
  • GetApprovedRecordsFromFormOnPage
  • GetApprovedRecordsFromForm
  • GetRecordsFromPage
  • GetRecordsFromFormOnPage
  • GetRecordsFromForm
  • The returned objects
  • Sample razor script

Was this helpful?

Edit on GitHub
Export as PDF
  1. Developer

Working With Record Data

Developer documentation on working with Forms record data.

Umbraco Forms includes some helper methods that return records of a given Form, which can be used to output records in your templates using razor.

Available Methods

The methods can be found by injecting the Umbraco.Forms.Core.Services.IRecordReaderService interface. For performance reasons, all these methods are paged.

GetApprovedRecordsFromPage

PagedResult<Record> GetApprovedRecordsFromPage(int pageId, int pageNumber, int pageSize)

Returns all records with the state set to approved from all Forms on the Umbraco page with the id = pageId .

GetApprovedRecordsFromFormOnPage

PagedResult<Record> GetApprovedRecordsFromFormOnPage(int pageId, Guid formId, int pageNumber, int pageSize)

Returns all records with the state set to approved from the Form with the id = formId on the Umbraco page with the id = pageId as a PagedResult<Record>.

GetApprovedRecordsFromForm

PagedResult<Record> GetApprovedRecordsFromForm(Guid formId, int pageNumber, int pageSize)

Returns all records with the state set to approved from the Form with the ID = formId as a PagedResult<Record>.

GetRecordsFromPage

PagedResult<Record> GetRecordsFromPage(int pageId, int pageNumber, int pageSize)

Returns all records from all Forms on the Umbraco page with the id = pageId as a PagedResult<Record>.

GetRecordsFromFormOnPage

PagedResult<Record> GetRecordsFromFormOnPage(int pageId, Guid formId, int pageNumber, int pageSize)

Returns all records from the Form with the id = formId on the Umbraco page with the id = pageId as a PagedResult<Record>.

GetRecordsFromForm

PagedResult<Record> GetRecordsFromForm(Guid formId, int pageNumber, int pageSize)

Returns all records from the Form with the ID = formId as a PagedResult<Record>.

The returned objects

All of these methods will return an object of type PagedResult<Record> so you can iterate through the Record objects.

The properties available on a Record are:

int Id
FormState State
DateTime Created
DateTime Updated
Guid Form
string IP
int UmbracoPageId
string MemberKey
Guid UniqueId
Dictionary<Guid, RecordField> RecordFields

In order to access custom Form fields, these are available in the RecordFields property. Furthermore there exists an extension method named ValueAsString on Record in Umbraco.Forms.Core.Extensions, such that you can get the value as string given the alias of the field.

This extension method handle multi value fields by comma separating the values. E.g. "A, B, C"

Sample razor script

Sample script that is outputting comments using a Form created with the default comment Form template.

@using Umbraco.Core;
@using Umbraco.Cms.Core.Composing;
@using Umbraco.Forms.Core.Extensions;
@inject IRecordReaderService _recordReaderService;

<ul id="comments">
    @foreach (var record in _recordReaderService.GetApprovedRecordsFromPage(Model.Id, 1, 10).Items)
    {
    <li>
        @record.Created.ToString("dd MMMM yyy")
        @if(string.IsNullOrEmpty(record.ValueAsString("email"))){
            <strong>@record.ValueAsString("name")</strong>
        }
        else{
            <strong>
                <a href="mailto:@record.ValueAsString("email")" target="_blank">@record.ValueAsString("name")</a>
            </strong>
        }
        <span>said</span>
        <p>@record.ValueAsString("comment")</p>
    </li>
    }
</ul>
PreviousEmail TemplatesNextUmbraco Forms in the Database

Last updated 5 months ago

Was this helpful?