Umbraco 7.2 + Forms (not Contour): How to get the RecordId from submitted Form on Post
In Contour I used the following code, but with the switch to Umbraco Forms I'm unable to retrieve the recordId from the first line (Request.QueryString["recordid"]). The goal is to create a simple report which uses a form to get user inputs and then POST back to itself and display the results while keeping the form visible on the page, something which worked with Contour (I've removed the call to the DLL and display logic from this example for simplicity).
I've also changed from using a Scripting File to a Partial View Macro File.
What is the proper means of obtaining the pointer to the data in the database after the successful POST?
To be clear, I am able to see the data in the Forms:Entries section so I know the form is working.
var recordId = Request.QueryString["recordid"]; Record record = storage.GetRecord(new Guid(recordId)); var recordFields = record.RecordFields;
foreach (var field in recordFields) { try { <div>@field.Value.ValuesAsString()</div> } catch (Exception e) { div style="color:red">@e.Message</div> } }
The imports in the Contour version look like this:
But I don't see how to grab the entry linked to the submission the current user created.
I will try using one of the following (I guess I didnt scroll far enough to see these). I'm guessing @Form.Id will work to get the form Guid? I haven't seen how to do that dynamically, I've only seen examples where the GUID is hard-coded into the code.
@CurrentPage.Id is the dynamic way of getting the current page id, and the Model.Id, is an earlier implmentation of Razor called DynamaicNode Razor, but this can not be used in Umbraco 7.2
Thanks for the links. Each of the methods in the documentation bring back all records and I only want the one.
The implementation on the next page is very similar to how I have the Countour version working, but the issue is still how to obtain the specific record from the current submission.
Ismail's post uses the recordId to retrieve the data which I've been unable to get back from Request.QueryString (with Forms implementation - it works with Contour). The blog-owner calls it submittedRecord, but I believe Ismail is referring to the same value in his example when he uses recordId (my reasoning is this pattern is found on other sites as well).
var submittedRecord = Request.QueryString["recordid"];
And while I've been able to find the Form GUID by looking at the CMS interface, I still don't see how to obtain it dynamically so I've used this which doesn't seem "right".
I have managed to hack it together, but I still resort to a for-loop to select the record-set matching the record id. I haven't found a method in the Library that accepts both a FormId and RecordId. While this isn't exactly how I have my site setup, here's a snippet of the loop in case it is useful.
var recordIdGuid = new Guid(TempData["Forms_Current_Record_id"].ToString());
var recordSet = Library.GetRecordsFromForm(@formId);
foreach (dynamic record in recordSet)
{
try
{
if (record.UniqueId.ToString() == recordIdGuid.ToString())
{
try
{
var myField = record.MyField;
var myDate = Regex.Unescape(record.MyDate);
var results = Html.Raw(MyDLLCall.GetAsJson(@myField, @myDate));
<table id="myDataTable" class="display"></table>
<script>jsonresults = @results;</script>
}
catch (Exception e)
{
<div style="color:red">@e.Message</div>
}
}
}
catch (Exception e)
{
<div style="color:red">@e.Message</div>
}
}
I still want to find a proper method in the Library as this is less than ideal, but performance hasn't been a hit (yet). Worst case I can probably hack it into the CMS somehow by hitting the underlying tables directly, but that may not work in an upgrade, so I've avoided it for now.
If you find something, please drop a note here. I'll do the same.
Umbraco 7.2 + Forms (not Contour): How to get the RecordId from submitted Form on Post
In Contour I used the following code, but with the switch to Umbraco Forms I'm unable to retrieve the recordId from the first line (Request.QueryString["recordid"]). The goal is to create a simple report which uses a form to get user inputs and then POST back to itself and display the results while keeping the form visible on the page, something which worked with Contour (I've removed the call to the DLL and display logic from this example for simplicity).
I've also changed from using a Scripting File to a Partial View Macro File.
What is the proper means of obtaining the pointer to the data in the database after the successful POST?
To be clear, I am able to see the data in the Forms:Entries section so I know the form is working.
The imports in the Contour version look like this:
The imports in the Forms version look like this:
Thanks -Greg
Hi Greg and welcome to our,
Try to see the documentation for Umbraco Forms on how to get data from a form on GitHub https://github.com/umbraco/UmbracoFormsDocumentation/blob/master/Developer/Working-With-Data/index.md
Hope this helps,
/Dennis
Hi Dennis,
I've been successful using the following to retrieve all records.
But I don't see how to grab the entry linked to the submission the current user created.
I will try using one of the following (I guess I didnt scroll far enough to see these). I'm guessing @Form.Id will work to get the form Guid? I haven't seen how to do that dynamically, I've only seen examples where the GUID is hard-coded into the code.
Thanks for the quick reply. I'll post back how it works.
<edit to cleanup @CurrentPage.Id vs @Model.Id>
Hi Greg,
@CurrentPage.Id is the dynamic way of getting the current page id, and the Model.Id, is an earlier implmentation of Razor called DynamaicNode Razor, but this can not be used in Umbraco 7.2
/Dennis
Dennis,
Thanks for the links. Each of the methods in the documentation bring back all records and I only want the one.
The implementation on the next page is very similar to how I have the Countour version working, but the issue is still how to obtain the specific record from the current submission.
Ismail's post uses the recordId to retrieve the data which I've been unable to get back from Request.QueryString (with Forms implementation - it works with Contour). The blog-owner calls it submittedRecord, but I believe Ismail is referring to the same value in his example when he uses recordId (my reasoning is this pattern is found on other sites as well).
And while I've been able to find the Form GUID by looking at the CMS interface, I still don't see how to obtain it dynamically so I've used this which doesn't seem "right".
Any thoughts on how to get the recordId in Forms?
Many thanks -Greg
Greg did you find a method to retrieve the current record id?
Best regards
Frederik
Frederik,
I have managed to hack it together, but I still resort to a for-loop to select the record-set matching the record id. I haven't found a method in the Library that accepts both a FormId and RecordId. While this isn't exactly how I have my site setup, here's a snippet of the loop in case it is useful.
I still want to find a proper method in the Library as this is less than ideal, but performance hasn't been a hit (yet). Worst case I can probably hack it into the CMS somehow by hitting the underlying tables directly, but that may not work in an upgrade, so I've avoided it for now.
If you find something, please drop a note here. I'll do the same.
Thanks -Greg
Thanks. I'll update the thread if I come up with something useful! /Frederik
Greg, I made the code a bit more generic to avoid manually maintaining guids. This gets the current form id from tempdata as well:
Also I created this feature request which will hopefully be in Forms 4.2: http://issues.umbraco.org/issue/CON-785
Great, and thanks for submitting a feature request!
Hi, I'm trying to get the data from a previously filled form using the recordId parameter, but it does not work
is working on a reply...