Copied to clipboard

Flag this post as spam?

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


  • Rob Smith 9 posts 70 karma points
    Sep 09, 2015 @ 16:26
    Rob Smith
    0

    Show the form after posting - Umbraco Forms

    I'm developing a site in Umbraco 7. Added "Umbraco Forms" for a basic comment functionality.

    However once posted the form disappears and shows the "thank you" message. I want the form to still be there so they can post another if they want to without refreshing the page.

    Looking at /Views/Partials/Forms/Form.cshtml

    It starts with

    @if (Model.SubmitHandled)
    {
        if (Model.RenderMode == "full" || Model.RenderMode == "form")
        {
            <p class="contourMessageOnSubmit">@Html.Raw(Model.MessageOnSubmit)</p>
            <p>Add another</p>
        }
    } else {
    

    So we get rid of the else bit, add in an extra @ or two because - well we all know razor is a bit of a dick

    And error....

    2015-09-09 16:51:37,265 [6] WARN  umbraco.macro - [P2904/T1/D2] Error loading Partial View (file: ~/Views/MacroPartials/RenderUmbracoFormScripts.cshtml). Exception: System.Web.HttpException (0x80004005): Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'. ---> System.NullReferenceException: Object reference not set to an instance of an object.
       at ASP._Page_Views_Partials_Forms_Form_cshtml.Execute() in d:\websiteName\v7\Views\Partials\Forms\Form.cshtml:line 142
    

    Line 142 is

    foreach (var script in Model.CurrentPage.JavascriptFiles)
    

    Of section

     @if (Model.RenderMode == "full" || Model.RenderMode == "script")
    {
        @Html.Partial(FormViewResolver.GetScriptView(Model.FormId), Model)
    
        foreach (var script in Model.CurrentPage.JavascriptFiles)
        {
            if (Model.UseClientDependency)
            {
                Html.RequiresJs(script.Value);
            }
            else
            {
                <script type="text/javascript" src="@Url.Content(script.Value)"></script>
            }
        }
    
        if (Model.CurrentPage.JavascriptCommands.Count > 0)
        {
    
            <script type="text/javascript">
                @foreach (var cmd in Model.CurrentPage.JavascriptCommands)
                {
                    <text>@Html.Raw(cmd)</text>
                }
    
            </script>
        }
    
        foreach (var css in Model.CurrentPage.CssFiles)
        {
            if (Model.UseClientDependency)
            {
                Html.RequiresCss(css.Value);
            }
            else
            {
                <link rel="stylesheet" href="@Url.Content(css.Value)" />
            }
        }
    
    }
    

    Any ideas?

  • Rob Smith 9 posts 70 karma points
    Oct 02, 2015 @ 16:41
    Rob Smith
    0

    So instead of trying to show the form after submit I just redirected on post back to the same page :)

    @if (Model.SubmitHandled)
    {
        if (Model.RenderMode == "full" || Model.RenderMode == "form")
        {
            Response.Redirect(Request.RawUrl + "#jumptothisID");
        }
    }
    
  • Rob Smith 9 posts 70 karma points
    Oct 05, 2015 @ 09:42
    Rob Smith
    101

    Oh and I only wanted to target the one specific form so I did this:

       @if (Model.SubmitHandled)
        {
            if (Model.RenderMode == "full" || Model.RenderMode == "form")
            {
                if (Model.FormId.Equals(new Guid("621dd31d-e7fb-4e1d-aa26-43d8d88a3f3f")))
                {
                 Response.Redirect(Request.RawUrl + "#jumptothisID");
                } else {
                  <p>Thanks you for submitting your form</p>
                }
            }
        }
        else
        {
            if (Model.RenderMode == "full" || Model.RenderMode == "form")
            {
    
Please Sign in or register to post replies

Write your reply to:

Draft