Copied to clipboard

Flag this post as spam?

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


  • Robert 6 posts 117 karma points
    Sep 01, 2022 @ 14:24
    Robert
    0

    Form summary

    Hi,

    I´ve been trying far too long to show a form summary of user input from a previous step.

    I think i have tried everything :)

    My plan is to create a new form field type which will loop through all entered values and show them in the form as a table or similar. I have successfully created the field type, have some other custom field types already, and can get the values using var form = TempData["umbracoformsform"] as FormViewModel;. However when using TempData all keys are Guid and thats not really descriptive so tried injecting IRecordReaderService but cannot get anything from any of the methods.

    How can i get keys and values from current form in order to show some sort of summary before posting the form?

    Thanks and best regards!

  • Robert 6 posts 117 karma points
    Sep 02, 2022 @ 06:53
    Robert
    100

    I have solved it, not sure this is the best way but its a way...

    @model Umbraco.Forms.Web.Models.FieldViewModel
    @using Umbraco.Forms.Core.Services
    @using Umbraco.Forms.Web.Models
    
    @inject IFormService _formService;
    
    @{
        var settings = Model.AdditionalSettings;
    
        var model = TempData["umbracoformsform"] as FormViewModel;
        var form = _formService.Get(model.FormId);
    }
    
    <div>
        <table>
            <thead>
                <tr>
                    <td></td>
                    <td></td>
                </tr>
            </thead>
            <tbody>
                @foreach (var state in model.FormState)
                {
                    var field = form.AllFields.FirstOrDefault(x => x.Id.ToString() == state.Key);
                    var value = state.Value;
    
                    <tr>
                        <td name="@field.Alias">@field.Caption</td>
                        <td>@value.FirstOrDefault()</td>
                    </tr>
                }
            </tbody>
        </table>
    </div>
    

    Please comment if anyone has a better solution.

Please Sign in or register to post replies

Write your reply to:

Draft