Skip to content

Commit 6438460

Browse files
authored
Document loading records from submitted forms
Added details for how to get the submitted record in a view file.
1 parent f90bf30 commit 6438460

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

16/umbraco-forms/developer/working-with-data.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,43 @@ Sample script that is outputting comments using a Form created with the default
110110
}
111111
</ul>
112112
```
113+
114+
## Loading a Record From a Submitted Form
115+
When a form is submitted, the submitted form id as well as the saved record id is stored in the TempData so it can be referenced.
116+
117+
You can use the FormService and the RecordStorage to get the ```Form``` and ```Record``` objects.
118+
119+
Here is sample code for how to get the record in a view.
120+
121+
```
122+
@using Umbraco.Forms.Core.Models
123+
@using Umbraco.Forms.Core.Persistence.Dtos
124+
@using Umbraco.Forms.Core.Data.Storage
125+
@using Umbraco.Forms.Core.Services
126+
@inject IFormService _formService
127+
@inject IRecordStorage _recordStorage
128+
@inherits UmbracoViewPage
129+
@{
130+
Guid formId;
131+
Form? form;
132+
Guid recordId;
133+
Record? record;
134+
string submittedEmail;
135+
136+
if (TempData["UmbracoFormSubmitted"] != null)
137+
{
138+
Guid.TryParse(TempData["UmbracoFormSubmitted"]?.ToString(), out formId);
139+
140+
form = _formService.Get(formId);
141+
142+
if (form != null && TempData["Forms_Current_Record_id"] != null)
143+
{
144+
Guid.TryParse(TempData["Forms_Current_Record_id"]?.ToString(), out recordId);
145+
146+
record = _recordStorage.GetRecordByUniqueId(recordId, form);
147+
148+
submittedEmail = record.GetRecordFieldByAlias("email")?.ValuesAsString();
149+
}
150+
}
151+
}
152+
```

0 commit comments

Comments
 (0)