Copied to clipboard

Flag this post as spam?

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


  • Tobias Nylin 24 posts 117 karma points
    Jul 14, 2016 @ 07:40
    Tobias Nylin
    0

    Umbraco adds scripts and css even if no form is inserted

    Hi! I've noticed that Umbraco adds both script and css to the source even if a forms isn't inserted on a page.

    It both calls InsertUmbracoForms.cshtml and Form.cshtml. If RenderMode for a form is "script" it will output the script and css to the source. So if I go to a page that doesn't have any form present, it will output all this code for every form.

    It seems unnecessary to me to output all this code if no form is inserted. I noticed that on pages that actually has a form present the form is first called with RenderMode = "form" and then RenderMode = "script", followed by all the other forms with RenderMode = "script".

    Has anyone else noticed this? Is there a trivial solution for hiding this code if no form is inserted?

    Thanks in advance!

  • Gavin Faux 15 posts 158 karma points
    Jul 14, 2016 @ 14:05
    Gavin Faux
    0

    Follow the guide for rendering scripts at the bottom of the page, and then in the template where you insert the Render Umbraco Forms Scripts, amend the code to check for presence of forms data:

    @if (TempData["UmbracoForms"] != null)
    {
        @Umbraco.RenderMacro("FormsRenderScripts")
    }
    

    Current version of forms (4.3.2) causes a client side javascript error (pikaday can't find node) if script is output and there is not a form in response.

  • Tobias Nylin 24 posts 117 karma points
    Jul 18, 2016 @ 12:00
    Tobias Nylin
    0

    Hi Gavin, thanks for the reply! I already have it set up so that it is rendering script at the bottom of the page, my code looks a bit different though.

    @if (TempData["UmbracoForms"] != null)
    {
        foreach (var form in (List<Guid>)TempData["UmbracoForms"])
        {
            Html.RenderAction("Render", "UmbracoForms", new { formId = form, mode = "script"});
        }
    }
    

    I noticed know though, for some reason TempData["UmbracoForms"] isn't null. If I debug the site on a page that does not have a form TempData["UmbracoForms"] contains two guids. This even happens if I restart the site.

  • [email protected] 395 posts 2067 karma points MVP 6x c-trib
    Oct 27, 2016 @ 13:51
  • Sebastiaan Janssen 4993 posts 15138 karma points MVP admin hq
    Jan 04, 2018 @ 14:00
    Sebastiaan Janssen
    0

    I just had a quick look at a possible fix, is anyone able to test the fix as suggested here?

    http://issues.umbraco.org/issue/CON-1199#comment=67-43731

Please Sign in or register to post replies

Write your reply to:

Draft