Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Greg 9 posts 29 karma points
    Jan 09, 2015 @ 21:29
    Greg
    0

    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:

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @using System.Web
    @using Umbraco.Forms.Mvc.DynamicObjects
    @using Umbraco.Forms.Data.Storage
    @using Umbraco.Forms.Core

    The imports in the Forms version look like this:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @using System.Web
    @using Umbraco.Forms.Mvc.DynamicObjects
    @using Umbraco.Forms.Data.Storage
    @using Umbraco.Forms.Core

    Thanks -Greg

     

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jan 09, 2015 @ 21:35
    Dennis Aaen
    0

    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

  • Greg 9 posts 29 karma points
    Jan 09, 2015 @ 21:42
    Greg
    0

    Hi Dennis,

    I've been successful using the following to retrieve all records.

    Library.GetApprovedRecordsFromPage(@CurrentPage.Id)

    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.

    GetRecordsFromForm(string formId)
    GetRecordsFromFormOnPage(int pageId, string formId)

    Thanks for the quick reply. I'll post back how it works.

    <edit to cleanup @CurrentPage.Id vs @Model.Id>

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jan 09, 2015 @ 22:04
    Dennis Aaen
    0

    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

  • Greg 9 posts 29 karma points
    Jan 09, 2015 @ 23:36
    Greg
    0

    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).

    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".

    var s = "bcc50f76-84eb-4e37-9ab2-dc9401ad6c09";

    Any thoughts on how to get the recordId in Forms?

    Many thanks -Greg

     

     

  • Frederik Raabye 72 posts 276 karma points MVP 2x c-trib
    Jun 24, 2015 @ 09:01
    Frederik Raabye
    0

    Greg did you find a method to retrieve the current record id?

    Best regards

    Frederik

  • Greg 9 posts 29 karma points
    Jun 24, 2015 @ 13:20
    Greg
    0

    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.

    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.

    Thanks -Greg

  • Frederik Raabye 72 posts 276 karma points MVP 2x c-trib
    Jun 24, 2015 @ 14:04
    Frederik Raabye
    0

    Thanks. I'll update the thread if I come up with something useful! /Frederik

  • Frederik Raabye 72 posts 276 karma points MVP 2x c-trib
    Jun 25, 2015 @ 08:57
    Frederik Raabye
    2

    Greg, I made the code a bit more generic to avoid manually maintaining guids. This gets the current form id from tempdata as well:

    @if (TempData["umbracoformsform"] != null && TempData["Forms_Current_Record_id"] != null)
    {
        var currentForm = (Umbraco.Forms.Mvc.Models.FormViewModel) TempData["umbracoformsform"];
        var currentRecordId = TempData["Forms_Current_Record_id"].ToString();
    
        var recordIdGuid = new Guid(currentRecordId);
        var recordSet = Library.GetRecordsFromForm(currentForm.FormId.ToString());
    
        foreach (dynamic record in recordSet)
        {
            try
            {
                if (record.UniqueId == recordIdGuid)
                {
                    <div>
                        <ul>
                            <li>Created:: @record.Created</li>
                            <li>Form:: @record.Form</li>
                            <li>Id:: @record.Id</li>
                            <li>IP:: @record.IP</li>
                            <li>MemberKey:: @record.MemberKey</li>
                            <li>State:: @record.State</li>
                            <li>UmbracoPageId:: @record.UmbracoPageId</li>
                            <li>Updated:: @record.Updated</li>
                            <li>UniqueId:: @record.UniqueId</li>
                        </ul>
                    </div>
                }
            }
            catch (Exception e)
            {
                <div>@e.Message</div>
            }
        }
    }
    

    Also I created this feature request which will hopefully be in Forms 4.2: http://issues.umbraco.org/issue/CON-785

  • Greg 9 posts 29 karma points
    Jun 25, 2015 @ 14:03
    Greg
    0

    Great, and thanks for submitting a feature request!

  • JMC 4 posts 74 karma points
    Mar 18, 2022 @ 16:05
    JMC
    0

    Hi, I'm trying to get the data from a previously filled form using the recordId parameter, but it does not work

    enter image description here

Please Sign in or register to post replies

Write your reply to:

Draft