Copied to clipboard

Flag this post as spam?

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


  • Thomas Beckert 193 posts 469 karma points
    Apr 24, 2019 @ 18:03
    Thomas Beckert
    0

    Umbraco Forms - Summary Page

    Hi,

    I'm about to use umbraco forms in a project, but my customer wants a summary page of the data entered by the user before the user submit the form. Is this possible? I did not find a way to do it with the GUI. I guess I have to hook up into the "page-process".

    Anyone any idea how to do this?

    Thanks for your ideas.

    Cheers,

    Tom

  • Mayur Deore 13 posts 146 karma points c-trib
    Apr 25, 2019 @ 05:24
    Mayur Deore
    100

    You can use Jquery for the same, and show summary in Modal Popup.

    You can do something like below.

    I have used bootstrap modal to show summary.

    <div id="form-summary-modal" class="modal fade" role="dialog">
            <div class="modal-dialog">
                <div class="modal-content"> 
                    <div class="modal-body"> 
                    </div>
                    <div class="modal-footer">
                        <button id="btnSubmit" type="button" class="btn btn-success">Submit</button>
                        <button id="btnCancel" type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    </div>
                </div>
    
            </div>
        </div>
    

    Using jquery form submit method.

    $("form").on("submit", function (e) {
                e.preventDefault();// This will prevent form submit
    
                var form = this;
                var formData = $(this).serializeArray();
    
                var html = GetFormDataInTable(formData)
    
    
                $("#form-summary-modal").modal("show");// Bootstrap Model
                $(".modal-body").html(html);
    
                // Unbind Existing Click event
                $("#btnSubmit").unbind("click");
    
    
                $("#btnSubmit").click(function () {
                    //Submit Form
    
                    $.post($(form).attr("action"), $(form).serializeArray(), function (response) {
                        //process response here
                        $("#myModal").modal("hide");
                        $(form).find("[type='submit']").removeAttr("disabled");
    
                        alert(response);
                    })
                })
                $("#btnCancel").click(function () {
                    //Cancel Form Submit
                    $("#myModal").modal("hide");
                    $(form).find("[type='submit']").removeAttr("disabled");
                })
                return false;
    
            })
    
            function GetFormDataInTable(formData) {
                // Create Table Element To Show Summary
                var html = document.createElement("table"); 
                html.setAttribute("class", "table");
    
                //loop form field array
                $.each(formData, function (i, v) {
                    if ($("[name=" + v.name + "]").is(":visible")) {
                        //append Each Form Field Data to table (only visible form fields)
                        $(html).append(GetFieldData(v));
                    }
                })
                return html;
            }
    
            function GetFieldData(field) {
    
                var name = $("[name=" + field.name + "]").parent("div").siblings("label").text();
                var value = field.value;
                var tr = $("<tr><td>" + name + "</td><td>" + value + "</td></tr>");
    
                return tr;
    
            }
    

    Note: I have considered default Umbraco Form Theme, to get Form Field Name.

  • Thomas Beckert 193 posts 469 karma points
    Apr 25, 2019 @ 10:08
    Thomas Beckert
    0

    Very good solution. Thank you for the code!

Please Sign in or register to post replies

Write your reply to:

Draft